C Codes
Beginners
C on Unix
Code Snippets
Data Structures
File Operations
Games Graphics
Gnu-Linux
Hardware
Mathematics
Miscellaneous
Small Programs
Sorting
C > Beginners Lab Assignments sample source codes
Prg. to sort any no. of numeral i-p in ascending or descending order.
Prg. to sort any no. of numeral i-p in ascending or descending order. void sort(void); int c,a[20],l; void main() { clrscr(); printf("Enter no. of elements in the list:- "); scanf ("%d",&l); printf(" CHOICE:-"); printf(" (1) Sort in ascending order."); printf(" (2) Sort in descending order."); printf(" CHOICE:- "); scanf("%d",&c); if (c!=1 && c!=2) { printf(" ERROR"); getch(); exit(0); } sort(); getch(); } void sort(void) { int n,i,j,temp=0,min,k; for (i=1;i<=l;i++) { printf(" Enter no.:- "); scanf("%d",&a[i]); } for (i=1;i<=(l-1);i++) { min=a[i]; k=i; for (j=(i+1);j<=l;j++) { if (a[j]
=1;i--) printf(" %d",a[i]); break; default: printf(" ERROR"); } return; }
Privacy Policy
|
Link to Us
|
Links