-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path05_conditionals.c
87 lines (75 loc) · 1.81 KB
/
05_conditionals.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include <stdio.h>
int main() {
int a = 10, b = 20, c = 15;
// if statement
printf("if statement:\n");
if (a < b) {
printf("a is less than b\n");
}
// if-else statement
printf("\nif-else statement:\n");
if (a > b) {
printf("a is greater than b\n");
} else {
printf("a is not greater than b\n");
}
// if-else if-else ladder
printf("\nif-else if-else ladder:\n");
if (a > b) {
printf("a is greater than b\n");
} else if (a == b) {
printf("a is equal to b\n");
} else {
printf("a is less than b\n");
}
// nested if
printf("\nnested if statement:\n");
if (a < b) {
if (c > a) {
printf("c is greater than a and a is less than b\n");
} else {
printf("c is not greater than a but a is less than b\n");
}
}
// switch statement
printf("\nswitch statement:\n");
int day = 3;
switch (day) {
case 1:
printf("Monday\n");
break;
case 2:
printf("Tuesday\n");
break;
case 3:
printf("Wednesday\n");
break;
case 4:
printf("Thursday\n");
break;
case 5:
printf("Friday\n");
break;
case 6:
printf("Saturday\n");
break;
case 7:
printf("Sunday\n");
break;
default:
printf("Invalid day\n");
break;
}
return 0;
}
/*if statement:
a is less than b
if-else statement:
a is not greater than b
if-else if-else ladder:
a is less than b
nested if statement:
c is greater than a and a is less than b
switch statement:
Wednesday
*/