+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
Session04 selection structure_b
1. Control Structure continued….
• Selection structures
• C has three types: if, if-else, and switch
• Repetition structures
• C has three types: while, do/while and for
2. Different forms of ‘if’ structures
If structure If and else structure If and else if structure
If(condition)
//…………………….
If(condition)
//…………………….
else
//……………………..
If(condition1)
//…………………….
else if(condition2)
//……………………..
else if(condition3)
//……………………..
else
//…………………
3. Nested Selection Structure
Nested if-else Structure
if (grade>=90)
printf(“A”);
else
if (grade>=80)
printf(“B”);
else
if (grade>=80)
printf(“C”);
else
if (grade>=60)
printf(“D”);
else
printf(“E”);
if (grade>=90)
printf(“A”);
else if (grade>=80)
printf(“B”);
else if (grade>=80)
printf(“C”);
else if (grade>=60)
printf(“D”);
else
printf(“E”);
4. Compound Statement Nested In if/else
if (grade>=60)
printf(“Passed”);
else {
printf(“Failed n”);
printf(“You must take the course again! ”);
}
Two lines
8. Logical Calculation
a !a
1 0
0 1
a b a&&b
1 1 1
1 0 0
0 1 0
0 0 0
a b a||b
1 1 1
1 0 1
0 1 1
0 0 0
!
&&
||
9. Use Of Logical Expression
int main() {
char c;
printf("Enter a Character ");
scanf("%c",&c);
if ((c>=‘A’&&c<=‘Z’)||(c>=‘a’&&c<=‘z’))
printf(“%c is a letter.”, c);
else if (c>=‘0’&& c<=‘9’)
printf(“%c is a digit.”, c);
else
printf(“%c is neither a letter nor a digit.”, c);
}