Write a program that will arrange the elements of a 10 integer array in descending order.
#include <stdio.h>
int main(){
//one dimensional array
int numbers[]={5,1,32,56,4,23,11,3,9,6};
int i,j;
//Sort array
for(i = 0; i<10; i++) {
for(j = i+1; j<10; j++){
if(numbers[j] > numbers[i]) {
int temp = numbers[i];
numbers[i] = numbers[j];
numbers[j] = temp;
}
}
}
printf("The elements of a 10 integer array in descending order:\n");
for(i=0;i<10;i++){
printf("%d\n",numbers[i]);
}
printf("\n");
getchar();
getchar();
return 0;
}
Comments
Leave a comment