SlideShare a Scribd company logo
1 of 9
Download to read offline
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)
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)
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)
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)
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)
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)
goto Statement
Format:
       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)
Any Question?




Md. Mahbub Alam   Structured Programming Language   8
                             (CSE-1121)
Thank You All




Md. Mahbub Alam     Structured Programming Language   9
                               (CSE-1121)

More Related Content

What's hot

Final project powerpoint template (fndprg) (1)
Final project powerpoint template (fndprg) (1)Final project powerpoint template (fndprg) (1)
Final project powerpoint template (fndprg) (1)
heoff
 
C Prog. - Decision & Loop Controls
C Prog. - Decision & Loop ControlsC Prog. - Decision & Loop Controls
C Prog. - Decision & Loop Controls
vinay arora
 
Joji ilagan career center foundation6final
Joji ilagan career center foundation6finalJoji ilagan career center foundation6final
Joji ilagan career center foundation6final
bluejayjunior
 

What's hot (19)

Decision making statements in C
Decision making statements in CDecision making statements in C
Decision making statements in C
 
4. loop
4. loop4. loop
4. loop
 
Final project powerpoint template (fndprg) (1)
Final project powerpoint template (fndprg) (1)Final project powerpoint template (fndprg) (1)
Final project powerpoint template (fndprg) (1)
 
Paradigmas de Linguagens de Programacao - Aula #5
Paradigmas de Linguagens de Programacao - Aula #5Paradigmas de Linguagens de Programacao - Aula #5
Paradigmas de Linguagens de Programacao - Aula #5
 
C Prog. - Decision & Loop Controls
C Prog. - Decision & Loop ControlsC Prog. - Decision & Loop Controls
C Prog. - Decision & Loop Controls
 
Joji ilagan career center foundation6final
Joji ilagan career center foundation6finalJoji ilagan career center foundation6final
Joji ilagan career center foundation6final
 
Flow control instructions
Flow control instructionsFlow control instructions
Flow control instructions
 
C operators
C operatorsC operators
C operators
 
Control Structure in C
Control Structure in CControl Structure in C
Control Structure in C
 
C Control Statements.docx
C Control Statements.docxC Control Statements.docx
C Control Statements.docx
 
Cprogrammingprogramcontrols
CprogrammingprogramcontrolsCprogrammingprogramcontrols
Cprogrammingprogramcontrols
 
Chapter 3
Chapter 3Chapter 3
Chapter 3
 
C++ STATEMENTS
C++ STATEMENTS C++ STATEMENTS
C++ STATEMENTS
 
Switch statement mcq
Switch statement  mcqSwitch statement  mcq
Switch statement mcq
 
Introduction to Basic C programming 02
Introduction to Basic C programming 02Introduction to Basic C programming 02
Introduction to Basic C programming 02
 
Control statement in c
Control statement in cControl statement in c
Control statement in c
 
Flow of control C ++ By TANUJ
Flow of control C ++ By TANUJFlow of control C ++ By TANUJ
Flow of control C ++ By TANUJ
 
Ch3 repetition
Ch3 repetitionCh3 repetition
Ch3 repetition
 
Control Flow Statements
Control Flow Statements Control Flow Statements
Control Flow Statements
 

Similar to Lecture04(control structure part i)

CONTROLSTRUCTURES.ppt
CONTROLSTRUCTURES.pptCONTROLSTRUCTURES.ppt
CONTROLSTRUCTURES.ppt
Sanjjaayyy
 
control stucture in c language
control stucture in c language control stucture in c language
control stucture in c language
abdulahi45
 

Similar to Lecture04(control structure part i) (20)

L3 control
L3 controlL3 control
L3 control
 
Lecture05(control structure part ii)
Lecture05(control structure part ii)Lecture05(control structure part ii)
Lecture05(control structure part ii)
 
Session 3
Session 3Session 3
Session 3
 
Control Statement programming
Control Statement programmingControl Statement programming
Control Statement programming
 
CONTROLSTRUCTURES.ppt
CONTROLSTRUCTURES.pptCONTROLSTRUCTURES.ppt
CONTROLSTRUCTURES.ppt
 
computer programming Control Statements.pptx
computer programming Control Statements.pptxcomputer programming Control Statements.pptx
computer programming Control Statements.pptx
 
LET US C (5th EDITION) CHAPTER 4 ANSWERS
LET US C (5th EDITION) CHAPTER 4 ANSWERSLET US C (5th EDITION) CHAPTER 4 ANSWERS
LET US C (5th EDITION) CHAPTER 4 ANSWERS
 
Fundamentals of programming)
Fundamentals of programming)Fundamentals of programming)
Fundamentals of programming)
 
Conditional statements
Conditional statementsConditional statements
Conditional statements
 
2013-06-15 - Software Craftsmanship mit JavaScript
2013-06-15 - Software Craftsmanship mit JavaScript2013-06-15 - Software Craftsmanship mit JavaScript
2013-06-15 - Software Craftsmanship mit JavaScript
 
2013-06-24 - Software Craftsmanship with JavaScript
2013-06-24 - Software Craftsmanship with JavaScript2013-06-24 - Software Craftsmanship with JavaScript
2013-06-24 - Software Craftsmanship with JavaScript
 
Perl Intro 4 Debugger
Perl Intro 4 DebuggerPerl Intro 4 Debugger
Perl Intro 4 Debugger
 
Decision Making and Branching
Decision Making and BranchingDecision Making and Branching
Decision Making and Branching
 
Virtual Separation of Concerns (2011 Update)
Virtual Separation of Concerns (2011 Update)Virtual Separation of Concerns (2011 Update)
Virtual Separation of Concerns (2011 Update)
 
control stucture in c language
control stucture in c language control stucture in c language
control stucture in c language
 
Elements of programming
Elements of programmingElements of programming
Elements of programming
 
Reversing & Malware Analysis Training Part 6 - Practical Reversing (I)
Reversing & Malware Analysis Training Part 6 -  Practical Reversing (I)Reversing & Malware Analysis Training Part 6 -  Practical Reversing (I)
Reversing & Malware Analysis Training Part 6 - Practical Reversing (I)
 
C notes.pdf
C notes.pdfC notes.pdf
C notes.pdf
 
What is c
What is cWhat is c
What is c
 
Final Exam in FNDPRG
Final Exam in FNDPRGFinal Exam in FNDPRG
Final Exam in FNDPRG
 

Recently uploaded

SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
CaitlinCummins3
 
MSc Ag Genetics & Plant Breeding: Insights from Previous Year JNKVV Entrance ...
MSc Ag Genetics & Plant Breeding: Insights from Previous Year JNKVV Entrance ...MSc Ag Genetics & Plant Breeding: Insights from Previous Year JNKVV Entrance ...
MSc Ag Genetics & Plant Breeding: Insights from Previous Year JNKVV Entrance ...
Krashi Coaching
 
The basics of sentences session 4pptx.pptx
The basics of sentences session 4pptx.pptxThe basics of sentences session 4pptx.pptx
The basics of sentences session 4pptx.pptx
heathfieldcps1
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
中 央社
 

Recently uploaded (20)

DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMDEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
 
An Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge AppAn Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge App
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptx
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
 
The Liver & Gallbladder (Anatomy & Physiology).pptx
The Liver &  Gallbladder (Anatomy & Physiology).pptxThe Liver &  Gallbladder (Anatomy & Physiology).pptx
The Liver & Gallbladder (Anatomy & Physiology).pptx
 
How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
 
MOOD STABLIZERS DRUGS.pptx
MOOD     STABLIZERS           DRUGS.pptxMOOD     STABLIZERS           DRUGS.pptx
MOOD STABLIZERS DRUGS.pptx
 
Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"
 
The Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFThe Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDF
 
MSc Ag Genetics & Plant Breeding: Insights from Previous Year JNKVV Entrance ...
MSc Ag Genetics & Plant Breeding: Insights from Previous Year JNKVV Entrance ...MSc Ag Genetics & Plant Breeding: Insights from Previous Year JNKVV Entrance ...
MSc Ag Genetics & Plant Breeding: Insights from Previous Year JNKVV Entrance ...
 
Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...
 
“O BEIJO” EM ARTE .
“O BEIJO” EM ARTE                       .“O BEIJO” EM ARTE                       .
“O BEIJO” EM ARTE .
 
IPL Online Quiz by Pragya; Question Set.
IPL Online Quiz by Pragya; Question Set.IPL Online Quiz by Pragya; Question Set.
IPL Online Quiz by Pragya; Question Set.
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024
 
The basics of sentences session 4pptx.pptx
The basics of sentences session 4pptx.pptxThe basics of sentences session 4pptx.pptx
The basics of sentences session 4pptx.pptx
 
Including Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdfIncluding Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdf
 
8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
 
demyelinated disorder: multiple sclerosis.pptx
demyelinated disorder: multiple sclerosis.pptxdemyelinated disorder: multiple sclerosis.pptx
demyelinated disorder: multiple sclerosis.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)
  • 7. goto Statement Format: 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. Any Question? Md. Mahbub Alam Structured Programming Language 8 (CSE-1121)
  • 9. Thank You All Md. Mahbub Alam Structured Programming Language 9 (CSE-1121)