Tuesday, 24 February 2015

Ascending Order Program Using C++

#include<iostream.h>
#include<conio.h>
main()
{
int a[100],n,i,j,sum=0;
clrscr();
cout<<"\n How Many Numbers You Want Give Input\n";
cin>>n;
cout<<"\n Enter Your Numbers\n";
for(i=0;i<n;i++)
{
cin>>a[i];
}

for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(a[i]<a[j])
{
int temp;
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}

cout<<"\n Sorted Numbers\n";
for(i=0;i<n;i++)
{
cout<<"\n"<<a[i];
}
getch();
}

No comments:

Post a Comment