Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote