Design a program in C, using the method of call by reference, which generates st
ID: 3764030 • Letter: D
Question
Design a program in C, using the method of call by reference, which generates statistics on the grades in a class consisting of M students and N quizzes given during the course of a semester. The quizzes all carry equal weighting, with the grade in each quiz being out of 10 points. The program is to do the following in the indicated sequence when the program is executed:
1. Ask the user to type on the keyboard the number of number of students M and the number of quizzes N, with M representing the number of rows and N representing the number of columns in a two-dimensional array x[M][N] of floating-point numbers.
2. Ask the user to type on the keyboard the values of all the elements of the array x[M][N].
3. Display on the console the M rows and N columns of inputted array element values.
4. Generate and display on the console the elements of a one-dimensional array p[M] where each element of this array p[M] represents the average grade over the semester of each of the M students.
5. Generate and display on the console the elements of a one-dimensional array q[N] where each element of q[N] represents the average grade in the class in each of the N quizzes .
6. Generate and display on the console the averge grade z for the entire class over the entire semester.
Explanation / Answer
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
int M,N,i,j;
//Part 1
printf("Enter Number of students M ");
scanf("%d",&M);
printf("Enter Number of quizzes ");
scanf("%d",&N);
float x[M][N],sum,p[M],q[N],z;
//Part 2
for(i=0;i<M;i++)
{
printf(" For student %d :: ", i+1);
for(j=0;j<N;j++)
{
printf("Grade for quiz %d::", j+1);
scanf("%f",&x[i][j]);
}
}
//Part 3
printf(" Displaying elements of x ");
for(i=0;i<M;i++)
{
for(j=0;j<N;j++)
printf("%.02f ", x[i][j]);
printf(" ");
}
//Part 4
printf(" Displaying Average grade of students over one semester ");
for(i=0;i<M;i++)
{
sum = 0;
for(j=0;j<N;j++)
sum+=x[i][j];
p[i] = sum/N;
}
for(i=0;i<M;i++)
{
printf("Student %d: %.02f ", i+1,p[i]);
}
//Part 5
printf(" Displaying Average of class in each quiz ");
for(j=0;j<N;j++)
{
sum = 0;
for(i=0;i<M;i++)
sum+=x[i][j];
q[j] = sum/M;
}
for(i=0;i<N;i++)
{
printf("Quiz %d: %.02f ", i+1,q[i]);
}
//Part 6
z = 0;
for(i=0;i<M;i++)
z += p[i];
printf(" Average Grade of Class over entire semester is %.02f ", z/M);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.