Programming for Problem Solving

GTU Practical 22

22. Write a program to calculate the average and total of 5 students for 3 subjects (use nested for loops)
#include<stdio.h>  ( this applies in the given code )

#include

int main() {
int sum, marks;

for (int i = 1; i <= 5; i++) { sum = 0; for (int j = 1; j <= 3; j++) { scanf("%d", &marks); sum += marks; } printf("Total: %d\n", sum); printf("Average: %.2f\n", sum / 3.0); } return 0; }

OUTPUT

Input:
10 20 30
15 25 35
40 50 60
22 28 34
12 18 24

Output:
Total: 60
Average: 20.00
Total: 75
Average: 25.00
Total: 150
Average: 50.00
Total: 84
Average: 28.00
Total: 54
Average: 18.00

GTU STUDY