Modify the program below (grades.c) from the class examples so that it sorts two
ID: 3530135 • Letter: M
Question
Modify the program below (grades.c) from the class examples so that it sorts two parallel arrays. Use the existing array of scores and add a parallel array of floating-point data to track a GPA(lowest 0.1; highest 4.0) that corresponds to the score in the other array. Sort and print the set of parallel arrays first by score, highest to lowest, then by GPA, highest to lowest. The inputs will be the number of pairs of entries (n) to be made, followed by n pairs of score & GPA. /* FILE: grades.c */ /* Loads an array with up to 50 values. Sorts the values into descending order. */ #include #define SIZE 50 int main( ) { int scores[SIZE]; int i, n, pass, item, position, temp; /* Get number of values to read */ printf("Please enter number of scores (%d or less): ", SIZE); scanf("%d", &n); /* Validate number entered by user. */ if (n<=SIZE && n>0){ /* Read score values into array */ for(i=0; i< scores[item]) position = item; if(pass != position){ temp = scores[pass]; scores[pass] = scores[position]; scores[position] = temp; } } /* Display scores in sorted order */ printf(" The scores in order. "); for(i=0; iExplanation / Answer
#include <stdio.h>
#define SIZE 50;
int main()
{
int scores[SIZE], n, i,j, , position, M;
float gpa[SIZE];
/* Get number of values to read */
printf("Enter number of scores (%d or less): ", SIZE);
scanf("%d", &n);/* Validate number entered by user. */
printf("Enter the maximum marks");
scanf("%d", &M );
printf("Enter %d integers ", n);
/* Read score values into scores */
for ( i = 0 ; i < n ; i++ )
scanf("%d", &scores[i]);
for ( i = n-1 ; i >=0 ; i-- )
{
position = i;
for ( j = i - 1 ; j>0 ; j-- )
{
if ( scores[position] > scores[j] )
position = j;
}
if ( position != i )
{
swap = scores[c];
scores[c] = scores[position];
scores[position] = swap;
}
}
/* evaluation of GPA */
for ( i = 0 ; i < n ; i++ )
{gpa[i]=(scores[i]/M)*10;
}
printf("Sorted list in descending order: ");
for ( i = 0 ; i < n ; i++ )
{printf("%d ", scores[i]);
printf("%d ", gpa[i]);
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.