arranging an array in ascending order

Joined
Dec 30, 2011
Messages
1
Reaction score
0
#include<iostream.h>
#include<conio.h>
void main()
{
int c[5]={4,7,9,8,1};
int i,j,k,temp,n;
int min=3;
for(j=0;j<5;j++)
{
for(i=j;i<5;i++)
{
if(c<min)
{
min=c;
}
}
for(k=0;k<5;k++)
{
if(min==c[k])
{
temp=c[k];
c[k]=c[j];
c[j]=temp;
}
}
}
for(n=0;n<5;n++)
cout<<c[n];
getch();
}
//i tried to use this program for arranging elements in ascending order in an array...it does not give the desired output...pls tell me the reason
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,992
Messages
2,570,220
Members
46,807
Latest member
ryef

Latest Threads

Top