SlideShare une entreprise Scribd logo
1  sur  9
Télécharger pour lire hors ligne
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)

Contenu connexe

Tendances

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
 

Tendances (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
 

Similaire à 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
 

Similaire à 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
 

Dernier

Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
negromaestrong
 

Dernier (20)

ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 

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)