Lecture04(control structure part i)

569 views
512 views

Published on

Published in: Education
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
569
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
24
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Lecture04(control structure part i)

  1. 1. Lecture04(Control Structure PART-I)June 22, 2010 Todays 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. 2. Simple if StatementFormat: 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. 3. if_else StatementFormat: 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. 4. else_if ladder StatementFormat: 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. 5. nested if_else StatementFormat: 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. 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)
  7. 7. goto StatementFormat: goto label; main() ......... { ......... double x,y; label: read: statements; scanf("%lf",&x); if(x<0) label: goto read; statements; y=sqrt(x); ......... printf("%lf",y); ......... } goto label; Md. Mahbub Alam Structured Programming Language 7 (CSE-1121)
  8. 8. Any Question?Md. Mahbub Alam Structured Programming Language 8 (CSE-1121)
  9. 9. Thank You AllMd. Mahbub Alam Structured Programming Language 9 (CSE-1121)

×