Enter integer:3
3
Enter integer:8
3
8
Enter integer:5
3
5
8
Tis is my coding:
#include <iostream>
using namespace std;
void bubblesort(int[],int);
int main(){
int num[5],x,i,y;
for( i=0;i<5;i++){
cout<<"Enter array index no. "<<i<<":";
cin>>num[i];}
bubblesort(num, 5);
for(int j = 0; j < 5; j++)
cout<<num[j]<<"\t";
return 0;
}
void bubblesort(int z[], int size)
{ int buffer;
for(int x = 0; x < 5; x++)
{ for(int y = x + 1; y < 5; y++)
{ if(z[x] > z[y])
{ buffer = z[x];
z[x] = z[y];
z[y] = buffer;
}
}
}
} my output
Enter array index no. 0:5
Enter array index no. 1:9
Enter array index no. 2:3
Enter array index no. 3:2
Enter array index no. 4:8
2 3 5 8 9 Press any key to continue . . .