-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNestedLoops.c
35 lines (28 loc) · 944 Bytes
/
NestedLoops.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// C Code
// This program will calculate the average of 3
// exams for a specified amount of students.
// Developer: Joseph Julian
#include <stdio.h>
int main(void) {
/* Variable Definition */
char name[100];
float sum, grade, average;
int students, total, exams;
printf("\nPlease enter how many students you wish to average grades for: ");
scanf("%d", &total);
// Loop through total students
for (students = 0; students < total; students++) {
printf("\nEnter 3 grades and student name: ");
sum = 0;
for (exams = 0; exams < 3; exams++) {
// float uses %f, double uses %lf
scanf("%f", &grade);
sum = sum + grade;
} // End for each exam
average = sum / 3;
scanf("%s", name);
printf("\nAverage for %s is %.2f\n", name, average);
} // End for each student
printf("\n... Bye ...");
return 0;
} // End main