1 Write a program that would ask the user to input marks of

1. Write a program that would ask the user to input marks of N (define as a preprocessor integer constant) number of quizzes in an array of size N.

After getting the input from the user and storing them in an array, you are required to write the following functions:

Print the grade of each quiz entered by the user using the following function prototype:
void print_quizzes(float A[], int size);
For each score, the function should call another function using the specified function prototype:

void print_grade(float score);
which displays a corresponding letter grade based on the following rules:

If the score is between 85.00 and 100.00 inclusive, display an \'A\'.

If the score is between 75.00 and 84.99 inclusive, display a \'B\'.

If the score is between 65.00 and 74.99 inclusive, display a \'C\'.

If the score is between 50.00 and 64.99 inclusive, display a \'D\'.

If the score is less than 50, display an \'F\'.

2. Calculate average marks and return the average to main program and print it there. Call the print_grade function from there passing the average as a parameter and print the grade associated with the average. Use the specified function prototype to calculate average: float cal_average(float A[],int size);

3. Find the highest marks obtained out of all the quizzes entered by the user using a function with specified function prototype:

float cal_max(float A[], int size);

4. Find the highest marks obtained out of all the quizzes entered by the user using a function with specified function prototype:

float cal_max(float A[], int size);

Solution

#include <stdio.h>
#define N 4 //Defining the no of quizzes
void print_quizzes(float A[], int size);
void print_grade(float score);
float cal_average(float A[],int size);
float cal_max(float A[], int size);

float cal_max(float A[], int size){
int index=0;
float max=0;
for(;index<size;index++) if(A[index] > max) max = A[index];
return max;
}

float cal_average(float A[],int size){
if(size < 1) return 0;
int index=0;
float sum=0;
for(;index<size;index++) sum+=A[index];
return sum/size;
}

void print_grade(float score){
printf(\"Grade for score = %f is \", score);
if(score>= 85.00 && score<= 100.00) printf(\"A\");
else if(score>= 75.00 && score<= 84.99) printf(\"B\");
else if(score>= 65.00 && score<= 74.99) printf(\"C\");
else if(score>= 50.00 && score<= 64.99) printf(\"D\");
else if(score < 50) printf(\"F\");
printf(\"\ \");
}

void print_quizzes(float A[], int size){
int index=0;
for(;index<size;index++)
print_grade(A[index]);
}

void main(){
float A[N];
int index=0;
for(;index<N;index++) {
printf(\"Enter the grade for %d quiz : \", index+1);
scanf(\"%f\", &A[index]);
}
print_quizzes(A, N);
float avg = cal_average(A, N);
printf(\"Avg score over the quizzes is : %f\ \", avg);
print_grade(avg);
float max = cal_max(A, N);
printf(\"Maximum score over the quizzes is : %f\ \", max);
print_grade(max);
}

1. Write a program that would ask the user to input marks of N (define as a preprocessor integer constant) number of quizzes in an array of size N. After gettin
1. Write a program that would ask the user to input marks of N (define as a preprocessor integer constant) number of quizzes in an array of size N. After gettin

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site