Prescribed medication order and communication skills.pptx
Lecture04(control structure part i)
1. Lecture04(Control Structure PART-I)
June 22, 2010
Today's Outline
Decision making statements in C
• Simple if statement
• if_else statement
• else_if ladder
• nested if_else statement
• switch statement
• goto statement
Md. Mahbub Alam Structured Programming Language 1
(CSE-1121)
2. Simple if Statement
Format:
If ( test condition )
statements;
scanf( “ %f “ , &marks );
if( marks >= 80 )
printf( "Yes, the student get A+“ );
Md. Mahbub Alam Structured Programming Language 2
(CSE-1121)
3. if_else Statement
Format:
if ( test condition )
statements;
else
statements;
if( num % 2 == 0 )
printf( “Even number“ );
else
printf( “Odd number” );
Md. Mahbub Alam Structured Programming Language 3
(CSE-1121)
4. else_if ladder Statement
Format:
if(condition 1) if( marks > 79 )
statements; printf( " Honours “ );
else if(condition 2) else if( marks > 59 )
statements; printf( " First Division “ );
else if(condition) else if( marks > 49 )
statements; printf( " Second Division “ );
.............. .. else if( marks > 39 )
.............. .. printf( " Third Division “ );
else if(condition n) else
statements; printf(" Fail ");
else
default statement;
Md. Mahbub Alam Structured Programming Language 4
(CSE-1121)
5. nested if_else Statement
Format:
if ( condition ) if(a>b)
if ( condition ) {
if(a>c)
statement1; printf("a is the largest:%d",a);
else else
statement2; printf("c is the largest:%d",c) ;
else }
statement3 else
{
if(c>b)
printf("c is the largest:%d",c);
else
printf("b is the largest:%d",b) ;
}
Md. Mahbub Alam Structured Programming Language 5
(CSE-1121)
6. switch Statement
index=marks/10;
Format: switch (index)
{
Switch ( expression ) case 10:
case 9:
{
case 8:
case constant1: printf(" Honours ");
statements; break;
break; case 7:
case 6:
case constant2:
printf(“ First Division ");
statements; break;
break; case 5:
............... printf(“ Second Division ");
break;
...............
case 4:
default: printf(“ Third Division ");
statements; break;
break; default:
} printf( “ Fail ");
break;
}
Md. Mahbub Alam Structured Programming Language 6
(CSE-1121)