ccplusplus.com
Learn C, C++ Concepts
Thursday, September 15, 2011
sort array in ascending order in c
/****************************************************** * File : sort-array-in-ascending-order.c * Author : Saurabh Gupta * Desc : sorting an array in ascending order * Source : http://saurabhgupta0527.blogspot.com/ * Created : AM 09:15 15 September 2011 * Note : *****************************************************/ #include
int main() { printf ("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n"); printf ("XXXXX array sorting in ascending order XXXXX\n"); printf ("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n"); int anInputNumbers[10], i, j,nTemp; printf("\nEnter 10 values of an array...........\n"); for(i=0; i<10; i++) { scanf("%d",&anInputNumbers[i]); } printf("\narray before sort .........\n"); for(i=0;i<10;i++) { printf("%d\t",anInputNumbers[i]); } for(i=0; i<9; i++) { for(j=i+1; j<10; j++) { if(anInputNumbers[i] <= anInputNumbers[j]) { nTemp = anInputNumbers[i]; anInputNumbers[i] = anInputNumbers[j]; anInputNumbers[j] = nTemp; } } } printf("\narray after sort .........\n"); for(i=0;i<10;i++) { printf("%d\t",anInputNumbers[i]); } printf ("\n"); printf ("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n"); return 0; } /* * * [sgupta@rhel54x64 c]$ gcc sort-array-in-ascending-order.c -o sort-array-in-ascending-order [sgupta@rhel54x64 c]$ ./sort-array-in-ascending-order XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXX array sorting in ascending order XXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Enter 10 values of an array........... 12 3 5 1 54 0 98 345 23 15 array before sort ......... 12 3 5 1 54 0 98 345 23 15 array after sort ......... 345 98 54 23 15 12 5 3 1 0 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX [sgupta@rhel54x64 c]$ */
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment