Test Scores #1 (required) Write a program that dynamically allocates an array la
ID: 3814534 • Letter: T
Question
Test Scores #1 (required) Write a program that dynamically allocates an array large enough to hold a user-defined number of test scores. Once all the scores are entered, the array should be passed to a function that sorts them in ascending order. Another function should be called that calculates the average score. The program should display the sorted list of scores and averages with appropriate headings. Use pointer notation rather than array notation whenever possible. Input Validation: Do not accept negative numbers for test scores. Your output should look like the following:Explanation / Answer
#include <stdio.h>
int main()
{
int num,i, * test_scores,j,temp,sum = 0;
printf("How many test scores will you enter?");
scanf("%d",num);
test_scores = malloc(num * sizeof(int*));
for(i=0 ; i<num ; i++)
{
printf(" enter test score %d : ",i);
scanf("%d",test_scores[i]);
}
for(i=0 ; i<num ; i++)
{
for(j=i ; j<num ; j++)
{
if(test_scores[j] > test_scores[j+1])
{
temp = test_scores[j+1];
test_scores[j+1] = test_scores[j];
test_scores[j] = temp;
}
}
}
printf("The test scores in ascending order, and their average, are score ..... ");
for(i=0 ; i<num ; i++)
{
printf("%d ",test_scores[i]);
sum = sum + test_scores[i];
}
printf(" Average score : %d ",sum);
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.