Sonu, 

and of course the loops control should be:

for (i=0;i<5;i++) {

            for (j=i+1; j<=5;j++) {

            // Do stuff.

            }

}

Moshe Okman

 

  _____  

From: Moshe Okman [mailto:mo...@okman.name] 
Sent: Friday, August 27, 2010 6:32 PM
To: c-prog@yahoogroups.com
Subject: RE: [c-prog] Help!!! :-(

 

  

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:sonuprajapat...@yahoo.in
<mailto:sonuprajapati89%40yahoo.in> ] 
Sent: Friday, August 27, 2010 5:37 AM
To: c-prog@yahoogroups.com <mailto:c-prog%40yahoogroups.com> 
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]





[Non-text portions of this message have been removed]

Reply via email to