#include #include #include int sorted[10]={0,0,0,0,0,0,0,0,0,0}; void sa(int tosort[]); void sd(int tosort[]); void main(void) { int tosort[10]; int i; char *sorttype="Ascending"; char sortify; clrscr(); printf("Enter the elements of the first array \n\r"); for(i=0;i<10;i++) scanf("%d",&tosort[i]); sorted[0]=tosort[0]; printf("Enter the TYPE of sort A: Ascending, D:Descending\n"); printf("(Entering NON A or D value will defult to A) "); sortify=getch(); switch(sortify) { case 'A': case 'a': { sa(tosort); printf("The %s sorted array is: \n",sorttype); break; } case 'd': case 'D': { sorttype="Descending"; sd(tosort); break; } default: { sa(tosort); break; } } printf("\nThe %s sorted array is: \n",sorttype); for(i=0;i<10;i++) { printf("%d\t",sorted[i]); delay(500); } } void sa(int tosort[]) { for(int i=1;i<10;i++) { for(int j=i-1;j>=0;j--) { if(tosort[i]>=sorted[j]) { sorted[j+1]=tosort[i]; break; } else { sorted[j+1]=sorted[j]; sorted[j]=0; if(j<1) { sorted[j]=tosort[i]; break; } } } } } void sd(int tosort[]) { for(int i=1;i<10;i++) { for(int j=i-1;j>=0;j--) { if(tosort[i]<=sorted[j]) { sorted[j+1]=tosort[i]; break; } else { sorted[j+1]=sorted[j]; sorted[j]=0; if(j<1) { sorted[j]=tosort[i]; break; } } } } }