C sorting arrays help

Status
Not open for further replies.

Cleong

Member level 2
Joined
Feb 17, 2006
Messages
53
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,789
How to write a simple code for sorting an array [2 6 1 7 9] for Descending Order

thanks
 

simplest way is bubble sort, sample code can be:

**broken link removed**
 

const int size =5;
int temp;
int x[size]={2, 6, 1, 7, 9};
for(int i=0;i<size-1;i++)
for(int j=i+1;j<size;j++)
if(x<x[j]){temp=x;x=x[j];x[j]=temp;}
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…