Control Structure Selection 4 Turbo C Version 3

������� Control Structure (Selection) (����� 4) ����� Turbo C++ Version 3. 0



�������� if if (age >= 18) printf("of agen"); printf("Good Luck"); age = 25 age = 14 age = 18 ������������� ? ? of age Good Luck


�������� if #include "stdio. h" main() { int magic = 123; // ���� 123 ������ int guess; printf("Enter your guess: "); scanf("%d", &guess); if (guess == magic) printf("**Right**"); } ������� ? Enter your guess: 100 Enter your guess: 123 ��������� **Right**



�������� if-else #include<stdio. h> #include<conio. h> void main(void) { int score; clrscr(); scanf("%d", &score); if (score >= 60) printf("You pass "); else printf("You fail "); printf("Have a nice day"); return; } ������� ? 59 You fail Have a nice day 79 You pass Have a nice day



���� if-else n ���������������������� main() ����������� { int magic = 123; //��������� 123 int guess; printf("Enter your guess"); scanf("%d", &guess); if(guess ? == magic) { ? printf("**Right**"); ? printf("%d ? is the magic number ", magic); } ? else ? (guess ? > magic)? printf("High") : printf("Low");

���� if-else n ����������������� 10 ������ 6. 5 �������� 10 �������� 7 ��� main() { int Number; float cost; printf("Enter number : "); scanf("%d", &Number); if(Number >= 10) cost = Number * 6. 5; else cost = Number * 7; printf("Cost = %0. 2 fn", cost); ����� ? Enter number : 5 Cost = 35. 00 Enter number : 10 Cost = 65. 00


�������� nested if statement n ��������������������� if(expr 1) false expr 1 true if(expr 2) statement 1; expr 2 stmt 3 else stmt 2 stmt 1 statement 2; else statement 3;



���� nested if statement #include <stdio. h> int main() { int a, b; printf("Please enter two integer: "); scanf("%d %d", &a, &b); if(a<=b) if(a<b) printf("%d < %dn", a, b); else printf("%d = %dn", a, b); else ����? printf("%d > %dn", a, b); return 0; Please enter two integer: -2 9 } -2 < 9


�������� if-else if #include<stdio. h> int x; main() { clrscr; printf("Enter Score(0. . 100): "); scanf("%d", &x) if(x>=90) ������ ? printf("EXCELLENT"); Enter Score(0. . 100): 70 else if(x>=80) FAIR printf("Good"); else if(x>=70) printf("FAIR"); ������ ? else Enter Score(0. . 100): 85 printf("FAIL"); GOOD }









������� Control Structure (Selection) Question ?
- Slides: 29