-
Notifications
You must be signed in to change notification settings - Fork 73
Expand file tree
/
Copy path06-conditional-statements.c
More file actions
73 lines (58 loc) · 1.64 KB
/
06-conditional-statements.c
File metadata and controls
73 lines (58 loc) · 1.64 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
/*
C if Statement
The syntax of the if statement in C programming is:
if (test expression)
{
// code
}
How if statement works?
The if statement evaluates the test expression inside the parenthesis ().
If the test expression is evaluated to true, statements inside the body of if are executed.
If the test expression is evaluated to false, statements inside the body of if are not executed.
Practice Program
Check if a number is negative
*/
/*
C if...else Statement
The if statement may have an optional else block. The syntax of the if..else statement is:
if (test expression) {
// run code if test expression is true
}
else {
// run code if test expression is false
}
How if...else statement works?
If the test expression is evaluated to true,
statements inside the body of if are executed.
statements inside the body of else are skipped from execution.
If the test expression is evaluated to false,
statements inside the body of else are executed
statements inside the body of if are skipped from execution.
Practice Program
Check whether a number is odd or even
*/
/*
C if...else Ladder
The if...else statement executes two different codes depending
upon whether the test expression is true or false. Sometimes,
a choice has to be made from more than 2 possibilities.
The if...else ladder allows you to check between multiple
test expressions and execute different statements.
Syntax of if...else Ladder
if (test expression1) {
// statement(s)
}
else if(test expression2) {
// statement(s)
}
else if (test expression3) {
// statement(s)
}
.
.
else {
// statement(s)
}
Practice Program
Program to relate two integers using ==, > or < symbol
*/