-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathswitch.c
56 lines (50 loc) · 836 Bytes
/
switch.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
/*
* Program to understand switch case statements
*/
#include <stdio.h>
int main () {
int dayNumber;
scanf("%d", &dayNumber);
/*
if (dayNumber == 1) {
printf("Its a Monday, funday!"\n);
}
else if (dayNumber == 2) {
printf("Tuesday!\n");
}
else if (dayNumber == 3) {
printf("Wednesday\n");
}
else if (dayNumber == 4) {
printf("Thursday\n");
}...
*/
// Switch case statements
switch(dayNumber) {
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("You have entered invalid day number.!\n");
break;
}
return 0;
}