Sonu Hi,
It looks like you have a problem with setting the loop indexes.
'i' should vary in range {0 to 4} and 'j' in range {1 to 5} since you always
compare between an element in the array with one of the following in the
array.
I hope this will solve your problem.
Moshe Okman
_____
From: Sonu Prajapati [mailto:[email protected]]
Sent: Friday, August 27, 2010 5:37 AM
To: [email protected]
Subject: [c-prog] Help!!! :-(
#include<iostream.h>
#include<conio.h>
void main()
{
int array[5],i,j,temp=0;
clrscr();
cout<<"Enter any five number:\n";
for(i=0;i<5;i++)
{
cin>>array[i];
}
for(i=0;i<5;i++)
{
for(j=0;j<i;j++)
{
if(array[j]>array[i])
{
temp=array[i];
array[i]=array[j];
array[j]=temp;
}
}
}
cout<<"The sorted array is:";
for(i=0;i<5;i++)
{
cout<<"\n"<<array[i];
}
getch();
}
[Non-text portions of this message have been removed]
[Non-text portions of this message have been removed]