# Session 5

## | Condition Session 5 Objectives Explain the Selection Construct - If Statement - If – else statement - Multi if statement - Nested if statement Switch statement Conditional Statement Conditional statements enable us to change the flow of the program A conditional statement evaluates to either a true or a false value Example : To find whether a number is even or odd we proceed as follows : Accept a number Find the remainder by dividing the number by 2 If the remainder is zero, the number is “EVEN” Or if the remainder is not zero the number is “ODD” Selection Constructs C supports two types of selection statements The if statement The switch statement The if statement-1 Syntax: If the if expression evaluates to true, the block following the if statement or statements are executed The if statement-2 #include void main() { int x, y; char a = ‘y’; x = y = 0; if (a == ‘y’) { x += 5; printf(“The numbers are %d and \t%d”, x, y); } } Program to display the values based on a condition Example The if – else statement-1 Syntax: The if – else statement-2 If the if expression does not evaluate to true then the statements following the else expression take over control The else statement is optional. It is used only if a statement or a sequence of statements are to be executed in case the if expression evaluates to false If the if expression evaluates to true, the block following the if statement or statements are executed The if – else statement -3 #include void main() { int num , res ; printf(“Enter a number :”); scanf(“%d”,&num); res = num % 2; if (res == 0) printf(“Then number is Even”); else printf(“The number is Odd”); } Program to display whether a number is Even or Odd Example The if–else–if statement-1 Syntax: The if – else – if statement is also known as the if-else-if ladder or the if-else-if staircase The conditions are evaluated from the top downwards The if–else–if statement-2 #include main() { int x; x = 0; clrscr (); printf(“Enter | Condition Session 5 Objectives Explain the Selection Construct - If Statement - If – else statement - Multi if statement - Nested if statement Switch statement Conditional Statement Conditional statements enable us to change the flow of the program A conditional statement evaluates to either a true or a false value Example : To find whether a number is even or odd we proceed as follows : Accept a number Find the remainder by dividing the number by 2 If the remainder is zero, the number is “EVEN” Or if the remainder is not zero the number is “ODD” Selection Constructs C supports two types of selection statements The if statement The switch statement The if statement-1 Syntax: If the if expression evaluates to true, the block following the if statement or statements are executed The if statement-2 #include void main() { int x, y; char a = ‘y’; x = y = 0; if (a == ‘y’) { x += 5; printf(“The numbers are %d and \t%d”, x, y); } } Program to display the values based on a condition

TÀI LIỆU LIÊN QUAN
32    57    1
25    199    2
7    63    0
55    301    6
23    153    0
23    97    0
7    45    0
41    75    12
17    31    2
9    482    32
TÀI LIỆU XEM NHIỀU
13    41237    2422
3    25184    250
25    24868    4300
16    20345    2847
20    19744    1550
14    19665    2977
1    19569    622
37    16431    2960
3    16403    331
1    14982    135
TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG
56    842    48    14-07-2024
2    348    1    14-07-2024
16    96    2    14-07-2024
4    205    1    14-07-2024
12    141    1    14-07-2024
5    382    1    14-07-2024
12    132    1    14-07-2024
26    87    1    14-07-2024
8    109    2    14-07-2024
91    74    3    14-07-2024
4    96    4    14-07-2024
5    95    2    14-07-2024
7    124    1    14-07-2024
63    162    2    14-07-2024
23    157    3    14-07-2024
41    336    3    14-07-2024
6    80    1    14-07-2024
113    87    2    14-07-2024
12    80    1    14-07-2024
6    198    3    14-07-2024
TÀI LIỆU HOT
3    25184    250
13    41237    2422
3    3017    81
580    5337    363
584    3572    101
62    6926    1
171    5940    721
2    3398    78
51    4693    200
53    4991    189
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.