-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathC_If_Else.c
44 lines (35 loc) · 1.15 KB
/
C_If_Else.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
#include <stdio.h>
int main()
{
/*Conditions and If Statements
You have already learned that C supports the usual logical conditions from mathematics:
Less than: a < b
Less than or equal to: a <= b
Greater than: a > b
Greater than or equal to: a >= b
Equal to a == b
Not Equal to: a != b
You can use these conditions to perform different actions for different decisions.
C has the following conditional statements:
Use if to specify a block of code to be executed, if a specified condition is true
Use else to specify a block of code to be executed, if the same condition is false
Use else if to specify a new condition to test, if the first condition is false
Use switch to specify many alternative blocks of code to be executed*/
int time = 22;
if (time < 10)
{
printf("Good morning!");
}
else if (time < 20)
{
printf("Good Day");
}
else
{
printf("Good evening!");
}
//Short Hand If...Else (Ternary Operator)
int newTime=20;
(time<18)? printf("Good Day."): printf("Good evening.");
return 0;
}