Apr 14, 2008 #1 C 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
Apr 14, 2008 #2 L linkfox Member level 2 Joined Dec 18, 2007 Messages 50 Helped 4 Reputation 8 Reaction score 1 Trophy points 1,288 Activity points 1,495 simplest way is bubble sort, sample code can be: **broken link removed**
Apr 30, 2008 #3 M mmelek1 Member level 4 Joined Apr 20, 2002 Messages 70 Helped 4 Reputation 8 Reaction score 1 Trophy points 1,288 Activity points 236 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;}
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;}