Sorted Array


Program to print the array in Ascending Order

 

#include<iostream>

#include<conio.h> 

int main()

{

int Info[]={6,3,8,2,9,4},MAX=0;

int ptr=0,j;

cout<<" Elements in an array "<<endl;

for(ptr=0;ptr<6;ptr++)

cout<<Info[ptr]<<endl;

cout<<endl<<"Sorted Array is: "<<endl;

for(ptr=0;ptr<6;ptr++)

{

for(j=6;j>=0;j--)

{

if(Info[j]<Info[j-1])

{

MAX=Info[j];

Info[j]=Info[j-1];

Info[j-1]=MAX;

}

}

cout<<endl<<Info[ptr];

}

getch();

return 0;

}

OUTPUT

No comments :

Post a Comment