summary refs log tree commit diff stats
path: root/assignments/01-grading-system.c
blob: 3c15f24a44e8035ce9efd3c347cc8c5a13d5a566 (plain) (blame)
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/* Grading system */
#include <stdio.h>

int main(void)
{
	int n1, n2, n3, n4;
	float avg;
	printf("Grading system\n\n");
	printf("Enter marks obtained in four subjects: ");
	scanf("%d%d%d%d", &n1, &n2, &n3, &n4);
	avg = (float)(n1 + n2 + n3 + n4)/4;
	printf("The average of the marks is %f\n", avg);
	if (avg >= 80)
		printf("The student has grade A.\n");
	if (avg >= 60 && avg < 80)
		printf("The student has grade B.\n");
	if (avg >= 40 && avg < 60)
		printf("The student has grade C.\n");
	if (avg < 40)
		printf("The student has failed.\n");
	return 0;
}

/*
Output:
Set 1:
Grading system

Enter marks obtained in four subjects: 81
85
86
91
The average of the marks is 85.750000
The student has grade A.

Set 2:
Grading system

Enter marks obtained in four subjects: 86 75 71 42
The average of the marks is 68.500000
The student has grade B.

Set 3:
Grading system

Enter marks obtained in four subjects: 45
55
51
42
The average of the marks is 48.250000
The student has grade C.

Set 4:
Grading system

Enter marks obtained in four subjects: 25
31
40 32
The average of the marks is 32.000000
The student has failed.

*/