Modify the code to be able to input any number of students (i.e. the loop is con
ID: 3598250 • Letter: M
Question
Modify the code to be able to input any number of students (i.e. the loop is controlled by the user input).
You will still only have 3 for each student. Support your experimentation with screen captures of executing the new code.
/ C code // This program will calculate the average of 3 exams for 5 students. // Developer Faculty CMIS102 // Date: Jan 31, XXXX #include int main () /*variable definition: * char StudentName [100] float ExamValue, Sum, Avg: int students, exams: // Loop through 5 Students for (students 0 studentsExplanation / Answer
#include<stdio.h>
int main()
{
char StudentName[100];
float exValue,Sum,Avg;
int students,ex,n;
printf("Enter number of students:");
scanf("%d",&n);
for(students=0;students<n;students++)
{
Sum=0.0;
printf("Enter Student Name ");
scanf("%s",StudentName);
for(ex=0;ex<3;ex++)
{
printf("Enter grade: ");
scanf("%f", &exValue);
Sum +=exValue;
}
Avg=Sum/3.0;
printf("Average for %s is %f ", StudentName,Avg);
}
return 0;
}
With this code you can able to input any number of students.
In the above code I have made some modification with for loop with 'n' which is numbe rof students that is given by user intead of 5
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.