-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path5_ConditionalSts.c
More file actions
94 lines (81 loc) · 1.5 KB
/
5_ConditionalSts.c
File metadata and controls
94 lines (81 loc) · 1.5 KB
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
88
89
90
91
92
93
94
#include <stdio.h>
/* Conditional Statements..
1. if-else
2. switch*/
int main()
{
/*If-else
if(condition){
// do something if true
}
else{
// do something if False
}*/
// int age;
// printf("Enter Age: ");
// scanf("%d", &age);
/*if(age>=18){
printf("You are an adult\nThey can vote");
}
else{
printf("You are not an adult");
}*/
/*Else if
if(condition1){
// do something if true
}
else if(condition2){
// do something if 1st false and 2nd true
}
else{
// do something if False
}
if(age>=18){
printf("adult");
}
else if(age>13 && age<18){
printf("teenager");
}
else{
printf("child");
}*/
/*Conditional Operators:
ternay:--
condition ? if true execute this : if false execute this
age>=18 ? printf("adult"):printf("not adult");*/
/*Switch
Properties:
a. cases can be in any order
b. Nested switch(switch inside switch) are allowed*/
// Print days using switch
int day;
printf("Enter day(1-7) : ");
scanf("%d", &day);
switch (day)
{
case 1:
printf("Monday");
break;
case 2:
printf("Tuesday");
break;
case 3:
printf("Wednesday");
break;
case 4:
printf("Thursday");
break;
case 5:
printf("Friday");
break;
case 6:
printf("Saturday");
break;
case 7:
printf("Sunday");
break;
default:
printf("Not a valid day");
}
return 0;
}