Write a program that allows the user to enter students’ names followed by their test scores and
outputs the following information (assume that maximum number of students is 50). Note you will
need to make use of an array.
a. The average score.
b. Names of all students whose test scores are below the average, with an appropriate
message.
c. Highest test score and the name of all students having the highest score.
#include <stdio.h>
#include <stdlib.h>
#define MAX_STUDENTS 50
struct Student
{
char name[20];
int score;
};
void InitializeStudents(struct Student students[])
{
int i;
for(i = 0; i < MAX_STUDENTS; ++i)
{
printf("Enter name and score of %d student!\n", i+1);
printf("Enter name: ");
scanf("%s", &students[i].name);
printf("Enter score: ");
scanf("%d", &students[i].score);
}
}
void PrintInfo(struct Student students[])
{
int i;
printf("\t\tInfo about students:\n\n");
for(i = 0; i < MAX_STUDENTS; ++i)
{
printf("The %s's score is %d\n", students[i].name, students[i].score);
}
}
int main()
{
struct Student students[MAX_STUDENTS];
InitializeStudents(students);
PrintInfo(students);
return 0;
}
Comments
Leave a comment