c++ program to sort predefined numbers
#include<iostream>
using namespace std;
//int sort_given_num(int arr[]);
int main()
{
int i,j,temp;
int arr[8]={12,10,14,18,2,20,7,30};
for(i=0;i<8;i++)
{
for(j=1;j<8;j++)
if(arr[j]<arr[i]);
{
temp=arr[i];
arr[j]=arr[i];
arr[i]=temp;
}
}
for(i=0;i<8;i++)
cout<<arr[i]<<endl;
}
OUT:
12
10
14
18
2
20
7
30
using namespace std;
//int sort_given_num(int arr[]);
int main()
{
int i,j,temp;
int arr[8]={12,10,14,18,2,20,7,30};
for(i=0;i<8;i++)
{
for(j=1;j<8;j++)
if(arr[j]<arr[i]);
{
temp=arr[i];
arr[j]=arr[i];
arr[i]=temp;
}
}
for(i=0;i<8;i++)
cout<<arr[i]<<endl;
}
OUT:
12
10
14
18
2
20
7
30
Comments
Post a Comment