Input 20 numbers. Arrange the numbers in ascending order and display ascending order as well as descending order list.
Write a program in C to input 20 integers and then print these integers in ascending order of magnitude and then in descending order of magnitude.
#include< #define N 20 void main( ) { int i, j, n[N], t; printf("Enter %d integer values\n", N); for (i=0; i < N; i++) scanf("%d", &n[i]); for(i=0; i < N-1; i++) for (j=i+1; j < N; j++) if (n[i] > n[j]) { t = n[i]; n[i] = n[j]; n[j] = t; } printf("The ascending order is \n"); for (i=0; i < N; i++) printf("%d\t", n[i]); printf("The descending order is \n"); for (i=N-1; i > = 0; i--) printf("%d", n[i]); getch( ); } |
---|
0 comments:
Post a Comment