-
Notifications
You must be signed in to change notification settings - Fork 0
/
15_Conditional_Operators.c
60 lines (49 loc) · 1.54 KB
/
15_Conditional_Operators.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
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
#include <stdio.h>
int main() {
int score;
printf("Enter the student's score (0-100): ");
scanf("%d", &score);
if (score >= 90) {
printf("Grade: A\n");
} else if (score >= 80) {
printf("Grade: B\n");
} else if (score >= 70) {
printf("Grade: C\n");
} else if (score >= 60) {
printf("Grade: D\n");
} else if (score >= 0) {
printf("Grade: F\n");
} else {
printf("Invalid score.\n");
}
return 0;
}
// Explanation
// 1
// if (score >= 90):
// This condition checks if the score is 90 or above.
// If true, it prints "Grade: A".
// 2
// else if (score >= 80):
// This condition is checked if the previous if condition is false.
// It checks if the score is 80 or above (but less than 90).
// If true, it prints "Grade: B".
// 3
// else if (score >= 70):
// This condition is checked if the previous else if condition is false.
// It checks if the score is 70 or above (but less than 80).
// If true, it prints "Grade: C".
// 4
// else if (score >= 60):
// This condition is checked if the previous else if condition is false.
// It checks if the score is 60 or above (but less than 70).
// If true, it prints "Grade: D".
// 5
// else if (score >= 0):
// This condition is checked if the previous else if condition is false.
// It checks if the score is 0 or above (but less than 60).
// If true, it prints "Grade: F".
// 6
// else:
// This block is executed if none of the previous conditions are true, which means the score is a negative value.
// It prints "Invalid score."