Friday 1 April 2016

Sort an Array Elements in Ascending Order in C++

Sort an Array Elements in Ascending Order in C++

A Program to write Sort an Array Elements in Ascending Order in C++ is very simple just follow the same concept which is apply in C programming to write this code.

Sort an Array Elements in Ascending Order in C++

Code:


#include<iostream.h>
#include<conio.h>
using namespace std;
void main()
{
int a[10],i,j,temp;

cout<<"Enter any 10 number:";
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])
{
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
}
for(i=0;i<10;i++)
cout<<"Elements in Accending Order:"
cout<<a[i]<<endl;
getch();
}

Output:

Enter any 10 number:
10
20
40
90
80
55
43
98
21
Elements in Accending Order:
10
20
21
40
43
55
80
90
98

No comments:

Post a Comment