In: Computer Science
Q: In a class there are ‘n’ students. All of them have
appeared for the test. The Teacher who evaluated the
sheets wants to know average marks of the class. Write code to help
the teacher find average
performance, use most appropriate data type/structure for storing
marks.
in c
programing language ....
CODE:
#include <stdio.h>
int main(void) {
int n;
printf("Enter the number of students\n");
scanf("%d",&n); //take input for number of students
int a[n];//declare array to store marks
printf("Enter the marks of %d students\n",n);
int sum=0;//declare sum variable to store sum of marks
for(int i=0;i<n;i++){
scanf("%d",&a[i]);//input the marks
sum=sum+a[i];//calculate the sum
}
float avg=sum/n;//calculate the average
printf("The average marks are %f",avg);//print the average
return 0;
}
OUTPUT: