60 578
Assignments Done
97,9%
Successfully Done
In April 2018

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.
Expert's answer

#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 first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions