Answer to Question #16420 in C++ for Andrew Lowrey

Question #16420
Write a program that takes in 10 (ten) test grades, display the unsorted grades, display the grades in ascending order, and then display the grades in descending order.
1
Expert's answer
2012-10-16T11:43:16-0400

#include <stdio.h>
#include <stdlib.h>

int grades[104] ;

int compare (const void * a, const void * b)
{
return ( *(int*)a - *(int*)b );
}

int main ()
{
int n;
for(int i=0;i<10;i++){
printf("Enter grade %d: ",(i+1));
scanf("%d",&grades[i]);
}
qsort (grades, 10, sizeof(int), compare);
for (n=9; n>=0; n--)
printf ("%d ",grades[n]);
scanf("%d",&grades[0]);
return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS