Answer to Question #148457 in C for Fero Lesper

Question #148457
Write a program that creates an array of N names. Each name has 5 exam scores. Output the names with the highest and lowest average scores.
1
Expert's answer
2020-12-03T07:30:09-0500
#include <stdio.h>
#include <stdlib.h>
int main()
{
    // we must declare the number names
    int n;
    printf("Enter the number of names: ");
    scanf("%d", &n);
    // we declare the array which consist of string names
    char *names[n];
    // We enter names for each number
    for (int i = 0; i < n; i++) {
        printf("Enter %d - name: ", (i + 1));
        scanf("%s", &names[i]);
    }
    // we can see the each names with their scores
    // last step is define the highest and lowest scores
    for (int i = 0; i < n; i++) {
        printf("%s - ", &names[i]);
        fillArray();
        printf("\n");
    }
    return 0;
}
// we fill the names with scores so we create a function for it
int fillArray () {
    int arr[5];
    int max = 0, min = 100;
    for (int i = 0; i < 5; i++) {
        arr[i] = rand() % 100;
        if (max < arr[i]) {
            max = arr[i];
        }
        if (min > arr[i]) {
            min = arr[i];
        }
        printf("%d ", arr[i]);
    }
    printf("\n%d - is highest score and %d - is the lowest score", max, min);
}

The proof is that the image which taken from console


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
New on Blog
APPROVED BY CLIENTS