#include <iostream>
//if you are in turbo compiler use<iostream.h> and sikp the only next line
using namespace std;
int main()
{
int arr[100],i,j,s,temp;
cout<<"enter array size";
cin>>s;
//taking input in array
for(i=0;i<s;i++)
{
cin>>arr[i];
}
//lets sort this array
for(i=0;i<s-1;i++)
{
for(j=0;j<s-1-i;j++)
{
if(arr[j]>arr[j+1])
{
temp=arr[j];
arr[j]=arr[j+1];
arr[j+1]=temp;
}
}
}
//here is your sorted array
for(i=0;i<s;i++)
{
cout<<arr[i]<<endl;
}
return 0;
}
//if you are in turbo compiler use<iostream.h> and sikp the only next line
using namespace std;
int main()
{
int arr[100],i,j,s,temp;
cout<<"enter array size";
cin>>s;
//taking input in array
for(i=0;i<s;i++)
{
cin>>arr[i];
}
//lets sort this array
for(i=0;i<s-1;i++)
{
for(j=0;j<s-1-i;j++)
{
if(arr[j]>arr[j+1])
{
temp=arr[j];
arr[j]=arr[j+1];
arr[j+1]=temp;
}
}
}
//here is your sorted array
for(i=0;i<s;i++)
{
cout<<arr[i]<<endl;
}
return 0;
}
No comments:
Post a Comment