Arrange the 10 Numbers into Ascending and Descending order :)
#include<iostream.h>
#include<conio.h>
void main()
{
int i,j,k,a[10];
clrscr();
cout<<"\n Enter 10 numbers: \n";
for(i=0;i<10;i++)
{
cin>>a[i];
}
for(i=0;i<10;i++)
{
for(j=0;j<10;j++)
{
if(a[i]>a[j])
{
k=a[i];
a[i]=a[j];
a[j]=k;
}
}
}
cout<<"\n Descending order\n";
for(i=0;i<10;i++)
{
cout<<a[i]<<" ";
}
cout<<"\n Ascending Order\n";
for(i=9;i!=-1;i--)
{
cout<<a[i]<<" ";
}
getch();
}
Here is the Output :))
No comments:
Post a Comment