SlideShare a Scribd company logo
Control Statement in C

 www.eshikshak.co.in
TYPES OF PROGRAMMING
STRUCTURE
•All modern programming languages include
support for three basic families of programming
structures:
•Sequential structures
•Decision structures
•Looping structures
WHAT IS A DECISION STRUCTURE?

 •Decision structures consist of:
 •Some type of T/F test
 •One or more executable blocks of code
 •Which block of code executes depends on the
 result of the T/F test (“the condition”).
CONTROL STATEMENT

•All the statements written in ‘C’ program executes
from top to bottom one by one
•Control statements are used to execute or transfer
the execution control from one part of the program
to another part based on a conditions, Such
statements are known as Conditional Statements
CONTROL STATEMENT

    •There are three types of control statements
used in C language
       1.if-else statement
       2.switch statement
       3.goto statement
IF / ELSE IF / ELSE                SELECTION
STRUCTURES
 1) A simple if structure is called a single-selection
 structure because it either selects or ignores a
 single action.

 2) The if / else structure is called a double-selection
 structure because it selects between two different
 actions.

 3) Nested if / else structures test for multiple cases
 by placing if / else structures inside other if / else
 structures.
RELATIONAL OPERATORS

To develop valid conditions, we need to use
relational operators.
 Operator      Meaning        Operator         Meaning


    >        Greater Than        <=      Less Than or Equal to

            Greater Than or
    >=                           ==            Equality
               Equal to

    <         Less Than          !=           Inequality
IF-ELSE STATEMENT

 •It is used to execute a set of statements or single
 statement based on the evaluation of given
 condition
 •It is basically a two way decision statement and is
 used in conjunction with an expression
TWO WAY BRANCHING
SIMPLE IF STATEMENT

        syntax :if(expression)
        {
                        statement 1;
                               statement 2;
                  .
True
                               statement N;
                                                                      }
         statement-x;
        Note : If expression is true than the set of statements will be
        executed after that statement-x will also be executed.
        Otherwise, the set of statements will be skipped and
        statements-x will be executed.
Result of expression

•Based on the             True   Non-Zero
evaluation of the
conditional expression
the result will be as
follow
                         False     Zero
EXAMPLE
void main()
{
                   int i=5;
        if(i==5)
                   {
                   printf(“You are inside the if true block”);
                             printf(“nvalue of i is equal to 5”);
                   }
                   printf(“nYou are outside the if block”);
}
output :
You are inside the if true block
value of i is equal to 5
   You are outside the if block
EXAMPLE
void main()
{
                   int i=-5;
        if(i==5)
                   {
                   printf(“You are inside the if true block”);
                             printf(“nvalue of i is equal to 5”);
                   }
                   printf(“nYou are outside the if block”);
}
output :
 You are outside the if block
IF-ELSE STATEMENT SYNTAX
       if (expression)
{
                 statement 1;
True                    statement 2;
                        .
                        .
                        statement N;
}
else
{
                 statement 1;
                        statement 2;
                        .     False
                        .
                        statement N;
}
IF-ELSE STATEMENT SYNTAX

The if selection structure is often written as:

        if ( this logical expression is true )    no semi-colon!
                   statement ;

And, the if / else selection structure is often written as:

        if ( this logical expression is true )
                   statement ;
        else
                    statement ;
A VERY SIMPLE PROGRAM:

           #include <stdio.h>
           int main ( )
           {
             int a = 1, b = 2, c ;

             if (a > b)
    {
        c = a;
    }
             else
         {
        c = b;
    }
}
A VERY SIMPLE PROGRAM:

           #include <stdio.h>
           int main ( )
           {
             int a = 1, b = 2, c ;

              if (a > b)
           c = a;
    else
               c = b;
}
IF…ELSE IF…ELSE STATEMENT

 •To perform multi-path decisions
 •It is collection of if statement with association of
 else statement
IF…ELSE IF…ELSE STATEMENT -
SYNTAX
 if(expression1)
 {
 statement 1;
 }
          else if(expression2)
          {
                    statement 2;
          }
                    else if(expression3)
                    {
                              statement 3;
                    }
                           else
                           {
                               statement 4; //Also known as default
 statement
                           }
IF…ELSE IF…ELSE STATEMENT

 •The structure is also known as else if ladder
 •The conditions are evaluated from top of the ladder
 to downwards
 •if the expression1 evaluates to true than all the
 statements in this block will executed
 •Execution pointer will jump to the statement
 immediately after the closing curly braces
 •If all the given conditions evaluates to false than all
 the statements in else block will be executed
 •Else block is also known as default statement
IF…ELSE IF…ELSE STATEMENT -
EXAMPLE
 void main()
 {
          int num;
          num=4;
          if(num>1)
          {
                   printf(“It is positive value”);
          }
                    else if(num<1)
                    {
                                printf(“It is negative value”);
                   }
                                else
                                 {
                                             printf(“It is zero value”):
                                 }
 getch();
 }
EXAMPLE

•WAP to accept marks for 5 subjects from the user,
calculate total and percentage and find the result as
per the following criteria
  Criteria                      Result
  Greater than or equal to 70   Distinction
  Between 60-70                 First Class
  Between 50-60                 Second Class
  Between 40-50                 Pass Class
  Less than 40                  Fail
EXAMPLE

Calculate the comission of a salesman considering
three regions X,Y and Z depending on the sales
amount as follow
 Area Code     Sales Amount   Comission
 X             <1000          10%
               <5000          12%
               >=5000         15%
 Y             <1500          10%
               <7000          12%
               >=7000         15%
 Z             <1200          10%
               <6500          12%
               >=6500         15%
EXAMPLE

•Big Bazzar gives festival discount on purchase of
their products in the following percentages
       i.If purchase amount < 1000 than 5% discount
       ii.If purchase amount >=1000 than but <3000 then
10% discount
       iii.If purchase amount >=3000 but <5000 then 12%
discount
       iv.If purchase amount > 5000 then 15% discount

More Related Content

What's hot

Branching statements
Branching statementsBranching statements
Branching statements
ArunMK17
 
Stacks overview with its applications
Stacks overview with its applicationsStacks overview with its applications
Stacks overview with its applicationsSaqib Saeed
 
If statements in c programming
If statements in c programmingIf statements in c programming
If statements in c programming
Archana Gopinath
 
Decision making statements in C programming
Decision making statements in C programmingDecision making statements in C programming
Decision making statements in C programming
Rabin BK
 
C++ STATEMENTS
C++ STATEMENTS C++ STATEMENTS
C++ STATEMENTS
Prof Ansari
 
While , For , Do-While Loop
While , For , Do-While LoopWhile , For , Do-While Loop
While , For , Do-While Loop
Abhishek Choksi
 
Constants Variables Datatypes by Mrs. Sowmya Jyothi
Constants Variables Datatypes by Mrs. Sowmya JyothiConstants Variables Datatypes by Mrs. Sowmya Jyothi
Constants Variables Datatypes by Mrs. Sowmya Jyothi
SowmyaJyothi3
 
If-else and switch-case
If-else and switch-caseIf-else and switch-case
If-else and switch-case
Manash Kumar Mondal
 
Control and conditional statements
Control and conditional statementsControl and conditional statements
Control and conditional statements
rajshreemuthiah
 
STRINGS IN C MRS.SOWMYA JYOTHI.pdf
STRINGS IN C MRS.SOWMYA JYOTHI.pdfSTRINGS IN C MRS.SOWMYA JYOTHI.pdf
STRINGS IN C MRS.SOWMYA JYOTHI.pdf
SowmyaJyothi3
 
10. switch case
10. switch case10. switch case
10. switch case
Way2itech
 
Unit II chapter 4 Loops in C
Unit II chapter 4 Loops in CUnit II chapter 4 Loops in C
Unit II chapter 4 Loops in C
Sowmya Jyothi
 
POINTERS IN C MRS.SOWMYA JYOTHI.pdf
POINTERS IN C MRS.SOWMYA JYOTHI.pdfPOINTERS IN C MRS.SOWMYA JYOTHI.pdf
POINTERS IN C MRS.SOWMYA JYOTHI.pdf
SowmyaJyothi3
 
Jumping statements
Jumping statementsJumping statements
Jumping statementsSuneel Dogra
 
Control statements in c
Control statements in cControl statements in c
Control statements in c
Sathish Narayanan
 
C if else
C if elseC if else
C if else
Ritwik Das
 
Control structures in c++
Control structures in c++Control structures in c++
Control structures in c++
Nitin Jawla
 
Compiler design syntax analysis
Compiler design syntax analysisCompiler design syntax analysis
Compiler design syntax analysis
Richa Sharma
 
Conditional statement c++
Conditional statement c++Conditional statement c++
Conditional statement c++
amber chaudary
 

What's hot (20)

Branching statements
Branching statementsBranching statements
Branching statements
 
Stacks overview with its applications
Stacks overview with its applicationsStacks overview with its applications
Stacks overview with its applications
 
If statements in c programming
If statements in c programmingIf statements in c programming
If statements in c programming
 
Decision making statements in C programming
Decision making statements in C programmingDecision making statements in C programming
Decision making statements in C programming
 
C++ STATEMENTS
C++ STATEMENTS C++ STATEMENTS
C++ STATEMENTS
 
While , For , Do-While Loop
While , For , Do-While LoopWhile , For , Do-While Loop
While , For , Do-While Loop
 
Constants Variables Datatypes by Mrs. Sowmya Jyothi
Constants Variables Datatypes by Mrs. Sowmya JyothiConstants Variables Datatypes by Mrs. Sowmya Jyothi
Constants Variables Datatypes by Mrs. Sowmya Jyothi
 
If-else and switch-case
If-else and switch-caseIf-else and switch-case
If-else and switch-case
 
Control and conditional statements
Control and conditional statementsControl and conditional statements
Control and conditional statements
 
STRINGS IN C MRS.SOWMYA JYOTHI.pdf
STRINGS IN C MRS.SOWMYA JYOTHI.pdfSTRINGS IN C MRS.SOWMYA JYOTHI.pdf
STRINGS IN C MRS.SOWMYA JYOTHI.pdf
 
Control structures in c
Control structures in cControl structures in c
Control structures in c
 
10. switch case
10. switch case10. switch case
10. switch case
 
Unit II chapter 4 Loops in C
Unit II chapter 4 Loops in CUnit II chapter 4 Loops in C
Unit II chapter 4 Loops in C
 
POINTERS IN C MRS.SOWMYA JYOTHI.pdf
POINTERS IN C MRS.SOWMYA JYOTHI.pdfPOINTERS IN C MRS.SOWMYA JYOTHI.pdf
POINTERS IN C MRS.SOWMYA JYOTHI.pdf
 
Jumping statements
Jumping statementsJumping statements
Jumping statements
 
Control statements in c
Control statements in cControl statements in c
Control statements in c
 
C if else
C if elseC if else
C if else
 
Control structures in c++
Control structures in c++Control structures in c++
Control structures in c++
 
Compiler design syntax analysis
Compiler design syntax analysisCompiler design syntax analysis
Compiler design syntax analysis
 
Conditional statement c++
Conditional statement c++Conditional statement c++
Conditional statement c++
 

Viewers also liked

Control statements
Control statementsControl statements
Control statements
Kanwalpreet Kaur
 
CONDITIONAL STATEMENT IN C LANGUAGE
CONDITIONAL STATEMENT IN C LANGUAGECONDITIONAL STATEMENT IN C LANGUAGE
CONDITIONAL STATEMENT IN C LANGUAGE
Ideal Eyes Business College
 
Html phrase tags
Html phrase tagsHtml phrase tags
Html phrase tags
eShikshak
 
Lecture15 comparisonoftheloopcontrolstructures.ppt
Lecture15 comparisonoftheloopcontrolstructures.pptLecture15 comparisonoftheloopcontrolstructures.ppt
Lecture15 comparisonoftheloopcontrolstructures.ppt
eShikshak
 
Lecture21 categoriesof userdefinedfunctions.ppt
Lecture21 categoriesof userdefinedfunctions.pptLecture21 categoriesof userdefinedfunctions.ppt
Lecture21 categoriesof userdefinedfunctions.ppt
eShikshak
 
Mesics lecture 5 input – output in ‘c’
Mesics lecture 5   input – output in ‘c’Mesics lecture 5   input – output in ‘c’
Mesics lecture 5 input – output in ‘c’
eShikshak
 
Mesics lecture 3 c – constants and variables
Mesics lecture 3   c – constants and variablesMesics lecture 3   c – constants and variables
Mesics lecture 3 c – constants and variables
eShikshak
 
Lecture 7 relational_and_logical_operators
Lecture 7 relational_and_logical_operatorsLecture 7 relational_and_logical_operators
Lecture 7 relational_and_logical_operators
eShikshak
 
Lecture7relationalandlogicaloperators 110823181038-phpapp02
Lecture7relationalandlogicaloperators 110823181038-phpapp02Lecture7relationalandlogicaloperators 110823181038-phpapp02
Lecture7relationalandlogicaloperators 110823181038-phpapp02eShikshak
 
Mesics lecture files in 'c'
Mesics lecture   files in 'c'Mesics lecture   files in 'c'
Mesics lecture files in 'c'
eShikshak
 
Algorithm
AlgorithmAlgorithm
Algorithm
eShikshak
 
Mesics lecture 7 iteration and repetitive executions
Mesics lecture 7   iteration and repetitive executionsMesics lecture 7   iteration and repetitive executions
Mesics lecture 7 iteration and repetitive executions
eShikshak
 
Unit 1.3 types of cloud
Unit 1.3 types of cloudUnit 1.3 types of cloud
Unit 1.3 types of cloud
eShikshak
 
Mesics lecture 8 arrays in 'c'
Mesics lecture 8   arrays in 'c'Mesics lecture 8   arrays in 'c'
Mesics lecture 8 arrays in 'c'
eShikshak
 
Unit 1.1 introduction to cloud computing
Unit 1.1   introduction to cloud computingUnit 1.1   introduction to cloud computing
Unit 1.1 introduction to cloud computing
eShikshak
 
Algorithm chapter 11
Algorithm chapter 11Algorithm chapter 11
Algorithm chapter 11chidabdu
 
Unit 1.2 move to cloud computing
Unit 1.2   move to cloud computingUnit 1.2   move to cloud computing
Unit 1.2 move to cloud computing
eShikshak
 
Lecture19 unionsin c.ppt
Lecture19 unionsin c.pptLecture19 unionsin c.ppt
Lecture19 unionsin c.ppteShikshak
 
Octal and Hexadecimal Numbering Systems
Octal and Hexadecimal Numbering SystemsOctal and Hexadecimal Numbering Systems
Octal and Hexadecimal Numbering Systems
Leo Hernandez
 
Html text and formatting
Html text and formattingHtml text and formatting
Html text and formattingeShikshak
 

Viewers also liked (20)

Control statements
Control statementsControl statements
Control statements
 
CONDITIONAL STATEMENT IN C LANGUAGE
CONDITIONAL STATEMENT IN C LANGUAGECONDITIONAL STATEMENT IN C LANGUAGE
CONDITIONAL STATEMENT IN C LANGUAGE
 
Html phrase tags
Html phrase tagsHtml phrase tags
Html phrase tags
 
Lecture15 comparisonoftheloopcontrolstructures.ppt
Lecture15 comparisonoftheloopcontrolstructures.pptLecture15 comparisonoftheloopcontrolstructures.ppt
Lecture15 comparisonoftheloopcontrolstructures.ppt
 
Lecture21 categoriesof userdefinedfunctions.ppt
Lecture21 categoriesof userdefinedfunctions.pptLecture21 categoriesof userdefinedfunctions.ppt
Lecture21 categoriesof userdefinedfunctions.ppt
 
Mesics lecture 5 input – output in ‘c’
Mesics lecture 5   input – output in ‘c’Mesics lecture 5   input – output in ‘c’
Mesics lecture 5 input – output in ‘c’
 
Mesics lecture 3 c – constants and variables
Mesics lecture 3   c – constants and variablesMesics lecture 3   c – constants and variables
Mesics lecture 3 c – constants and variables
 
Lecture 7 relational_and_logical_operators
Lecture 7 relational_and_logical_operatorsLecture 7 relational_and_logical_operators
Lecture 7 relational_and_logical_operators
 
Lecture7relationalandlogicaloperators 110823181038-phpapp02
Lecture7relationalandlogicaloperators 110823181038-phpapp02Lecture7relationalandlogicaloperators 110823181038-phpapp02
Lecture7relationalandlogicaloperators 110823181038-phpapp02
 
Mesics lecture files in 'c'
Mesics lecture   files in 'c'Mesics lecture   files in 'c'
Mesics lecture files in 'c'
 
Algorithm
AlgorithmAlgorithm
Algorithm
 
Mesics lecture 7 iteration and repetitive executions
Mesics lecture 7   iteration and repetitive executionsMesics lecture 7   iteration and repetitive executions
Mesics lecture 7 iteration and repetitive executions
 
Unit 1.3 types of cloud
Unit 1.3 types of cloudUnit 1.3 types of cloud
Unit 1.3 types of cloud
 
Mesics lecture 8 arrays in 'c'
Mesics lecture 8   arrays in 'c'Mesics lecture 8   arrays in 'c'
Mesics lecture 8 arrays in 'c'
 
Unit 1.1 introduction to cloud computing
Unit 1.1   introduction to cloud computingUnit 1.1   introduction to cloud computing
Unit 1.1 introduction to cloud computing
 
Algorithm chapter 11
Algorithm chapter 11Algorithm chapter 11
Algorithm chapter 11
 
Unit 1.2 move to cloud computing
Unit 1.2   move to cloud computingUnit 1.2   move to cloud computing
Unit 1.2 move to cloud computing
 
Lecture19 unionsin c.ppt
Lecture19 unionsin c.pptLecture19 unionsin c.ppt
Lecture19 unionsin c.ppt
 
Octal and Hexadecimal Numbering Systems
Octal and Hexadecimal Numbering SystemsOctal and Hexadecimal Numbering Systems
Octal and Hexadecimal Numbering Systems
 
Html text and formatting
Html text and formattingHtml text and formatting
Html text and formatting
 

Similar to Mesics lecture 6 control statement = if -else if__else

Flow of control C ++ By TANUJ
Flow of control C ++ By TANUJFlow of control C ++ By TANUJ
Flow of control C ++ By TANUJ
TANUJ ⠀
 
Control structures IN SWIFT
Control structures IN SWIFTControl structures IN SWIFT
Control structures IN SWIFT
LOVELY PROFESSIONAL UNIVERSITY
 
Introduction to computer programming (C)-CSC1205_Lec5_Flow control
Introduction to computer programming (C)-CSC1205_Lec5_Flow controlIntroduction to computer programming (C)-CSC1205_Lec5_Flow control
Introduction to computer programming (C)-CSC1205_Lec5_Flow control
ENGWAU TONNY
 
Control statments in c
Control statments in cControl statments in c
Control statments in c
CGC Technical campus,Mohali
 
Basics of Control Statement in C Languages
Basics of Control Statement in C LanguagesBasics of Control Statement in C Languages
Basics of Control Statement in C Languages
Chandrakant Divate
 
Control Flow Statements
Control Flow Statements Control Flow Statements
Control Flow Statements
Tarun Sharma
 
C-Programming Control statements.pptx
C-Programming Control statements.pptxC-Programming Control statements.pptx
C-Programming Control statements.pptx
SKUP1
 
C-Programming Control statements.pptx
C-Programming Control statements.pptxC-Programming Control statements.pptx
C-Programming Control statements.pptx
LECO9
 
Loops and conditional statements
Loops and conditional statementsLoops and conditional statements
Loops and conditional statements
Saad Sheikh
 
Session 3
Session 3Session 3
3-Conditional-if-else-switch btech computer in c.pdf
3-Conditional-if-else-switch btech computer in c.pdf3-Conditional-if-else-switch btech computer in c.pdf
3-Conditional-if-else-switch btech computer in c.pdf
ArkSingh7
 
Ch5 Selection Statements
Ch5 Selection StatementsCh5 Selection Statements
Ch5 Selection Statements
SzeChingChen
 
05 Conditional statements
05 Conditional statements05 Conditional statements
05 Conditional statements
maznabili
 
programming c language.
programming c language. programming c language.
programming c language.
Abdul Rehman
 
Constructs (Programming Methodology)
Constructs (Programming Methodology)Constructs (Programming Methodology)
Constructs (Programming Methodology)
Jyoti Bhardwaj
 
Unit_3A_If_Else_Switch and a if else statment example
Unit_3A_If_Else_Switch and a if else statment exampleUnit_3A_If_Else_Switch and a if else statment example
Unit_3A_If_Else_Switch and a if else statment example
umaghosal12101974
 
Control statements anil
Control statements anilControl statements anil
Control statements anil
Anil Dutt
 
Flow of Control
Flow of ControlFlow of Control
Flow of Control
Praveen M Jigajinni
 
CONTROL STMTS.pptx
CONTROL STMTS.pptxCONTROL STMTS.pptx
CONTROL STMTS.pptx
JavvajiVenkat
 
control statement
control statement control statement
control statement
Kathmandu University
 

Similar to Mesics lecture 6 control statement = if -else if__else (20)

Flow of control C ++ By TANUJ
Flow of control C ++ By TANUJFlow of control C ++ By TANUJ
Flow of control C ++ By TANUJ
 
Control structures IN SWIFT
Control structures IN SWIFTControl structures IN SWIFT
Control structures IN SWIFT
 
Introduction to computer programming (C)-CSC1205_Lec5_Flow control
Introduction to computer programming (C)-CSC1205_Lec5_Flow controlIntroduction to computer programming (C)-CSC1205_Lec5_Flow control
Introduction to computer programming (C)-CSC1205_Lec5_Flow control
 
Control statments in c
Control statments in cControl statments in c
Control statments in c
 
Basics of Control Statement in C Languages
Basics of Control Statement in C LanguagesBasics of Control Statement in C Languages
Basics of Control Statement in C Languages
 
Control Flow Statements
Control Flow Statements Control Flow Statements
Control Flow Statements
 
C-Programming Control statements.pptx
C-Programming Control statements.pptxC-Programming Control statements.pptx
C-Programming Control statements.pptx
 
C-Programming Control statements.pptx
C-Programming Control statements.pptxC-Programming Control statements.pptx
C-Programming Control statements.pptx
 
Loops and conditional statements
Loops and conditional statementsLoops and conditional statements
Loops and conditional statements
 
Session 3
Session 3Session 3
Session 3
 
3-Conditional-if-else-switch btech computer in c.pdf
3-Conditional-if-else-switch btech computer in c.pdf3-Conditional-if-else-switch btech computer in c.pdf
3-Conditional-if-else-switch btech computer in c.pdf
 
Ch5 Selection Statements
Ch5 Selection StatementsCh5 Selection Statements
Ch5 Selection Statements
 
05 Conditional statements
05 Conditional statements05 Conditional statements
05 Conditional statements
 
programming c language.
programming c language. programming c language.
programming c language.
 
Constructs (Programming Methodology)
Constructs (Programming Methodology)Constructs (Programming Methodology)
Constructs (Programming Methodology)
 
Unit_3A_If_Else_Switch and a if else statment example
Unit_3A_If_Else_Switch and a if else statment exampleUnit_3A_If_Else_Switch and a if else statment example
Unit_3A_If_Else_Switch and a if else statment example
 
Control statements anil
Control statements anilControl statements anil
Control statements anil
 
Flow of Control
Flow of ControlFlow of Control
Flow of Control
 
CONTROL STMTS.pptx
CONTROL STMTS.pptxCONTROL STMTS.pptx
CONTROL STMTS.pptx
 
control statement
control statement control statement
control statement
 

More from eShikshak

Modelling and evaluation
Modelling and evaluationModelling and evaluation
Modelling and evaluation
eShikshak
 
Operators in python
Operators in pythonOperators in python
Operators in python
eShikshak
 
Datatypes in python
Datatypes in pythonDatatypes in python
Datatypes in python
eShikshak
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
eShikshak
 
Introduction to e commerce
Introduction to e commerceIntroduction to e commerce
Introduction to e commerce
eShikshak
 
Chapeter 2 introduction to cloud computing
Chapeter 2   introduction to cloud computingChapeter 2   introduction to cloud computing
Chapeter 2 introduction to cloud computing
eShikshak
 
Unit 1.4 working of cloud computing
Unit 1.4 working of cloud computingUnit 1.4 working of cloud computing
Unit 1.4 working of cloud computing
eShikshak
 
Mesics lecture 4 c operators and experssions
Mesics lecture  4   c operators and experssionsMesics lecture  4   c operators and experssions
Mesics lecture 4 c operators and experssionseShikshak
 
Mesics lecture 5 input – output in ‘c’
Mesics lecture 5   input – output in ‘c’Mesics lecture 5   input – output in ‘c’
Mesics lecture 5 input – output in ‘c’eShikshak
 
Lecture20 user definedfunctions.ppt
Lecture20 user definedfunctions.pptLecture20 user definedfunctions.ppt
Lecture20 user definedfunctions.ppt
eShikshak
 
Lecture18 structurein c.ppt
Lecture18 structurein c.pptLecture18 structurein c.ppt
Lecture18 structurein c.ppt
eShikshak
 
Lecture17 arrays.ppt
Lecture17 arrays.pptLecture17 arrays.ppt
Lecture17 arrays.ppt
eShikshak
 
Lecture13 control statementswitch.ppt
Lecture13 control statementswitch.pptLecture13 control statementswitch.ppt
Lecture13 control statementswitch.ppt
eShikshak
 
Lecturer23 pointersin c.ppt
Lecturer23 pointersin c.pptLecturer23 pointersin c.ppt
Lecturer23 pointersin c.ppteShikshak
 
Program development cyle
Program development cyleProgram development cyle
Program development cyle
eShikshak
 
Language processors
Language processorsLanguage processors
Language processorseShikshak
 
Computer programming programming_langugages
Computer programming programming_langugagesComputer programming programming_langugages
Computer programming programming_langugages
eShikshak
 

More from eShikshak (17)

Modelling and evaluation
Modelling and evaluationModelling and evaluation
Modelling and evaluation
 
Operators in python
Operators in pythonOperators in python
Operators in python
 
Datatypes in python
Datatypes in pythonDatatypes in python
Datatypes in python
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Introduction to e commerce
Introduction to e commerceIntroduction to e commerce
Introduction to e commerce
 
Chapeter 2 introduction to cloud computing
Chapeter 2   introduction to cloud computingChapeter 2   introduction to cloud computing
Chapeter 2 introduction to cloud computing
 
Unit 1.4 working of cloud computing
Unit 1.4 working of cloud computingUnit 1.4 working of cloud computing
Unit 1.4 working of cloud computing
 
Mesics lecture 4 c operators and experssions
Mesics lecture  4   c operators and experssionsMesics lecture  4   c operators and experssions
Mesics lecture 4 c operators and experssions
 
Mesics lecture 5 input – output in ‘c’
Mesics lecture 5   input – output in ‘c’Mesics lecture 5   input – output in ‘c’
Mesics lecture 5 input – output in ‘c’
 
Lecture20 user definedfunctions.ppt
Lecture20 user definedfunctions.pptLecture20 user definedfunctions.ppt
Lecture20 user definedfunctions.ppt
 
Lecture18 structurein c.ppt
Lecture18 structurein c.pptLecture18 structurein c.ppt
Lecture18 structurein c.ppt
 
Lecture17 arrays.ppt
Lecture17 arrays.pptLecture17 arrays.ppt
Lecture17 arrays.ppt
 
Lecture13 control statementswitch.ppt
Lecture13 control statementswitch.pptLecture13 control statementswitch.ppt
Lecture13 control statementswitch.ppt
 
Lecturer23 pointersin c.ppt
Lecturer23 pointersin c.pptLecturer23 pointersin c.ppt
Lecturer23 pointersin c.ppt
 
Program development cyle
Program development cyleProgram development cyle
Program development cyle
 
Language processors
Language processorsLanguage processors
Language processors
 
Computer programming programming_langugages
Computer programming programming_langugagesComputer programming programming_langugages
Computer programming programming_langugages
 

Recently uploaded

Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
g2nightmarescribd
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 

Recently uploaded (20)

Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 

Mesics lecture 6 control statement = if -else if__else

  • 1. Control Statement in C www.eshikshak.co.in
  • 2. TYPES OF PROGRAMMING STRUCTURE •All modern programming languages include support for three basic families of programming structures: •Sequential structures •Decision structures •Looping structures
  • 3. WHAT IS A DECISION STRUCTURE? •Decision structures consist of: •Some type of T/F test •One or more executable blocks of code •Which block of code executes depends on the result of the T/F test (“the condition”).
  • 4. CONTROL STATEMENT •All the statements written in ‘C’ program executes from top to bottom one by one •Control statements are used to execute or transfer the execution control from one part of the program to another part based on a conditions, Such statements are known as Conditional Statements
  • 5. CONTROL STATEMENT •There are three types of control statements used in C language 1.if-else statement 2.switch statement 3.goto statement
  • 6. IF / ELSE IF / ELSE SELECTION STRUCTURES 1) A simple if structure is called a single-selection structure because it either selects or ignores a single action. 2) The if / else structure is called a double-selection structure because it selects between two different actions. 3) Nested if / else structures test for multiple cases by placing if / else structures inside other if / else structures.
  • 7. RELATIONAL OPERATORS To develop valid conditions, we need to use relational operators. Operator Meaning Operator Meaning > Greater Than <= Less Than or Equal to Greater Than or >= == Equality Equal to < Less Than != Inequality
  • 8. IF-ELSE STATEMENT •It is used to execute a set of statements or single statement based on the evaluation of given condition •It is basically a two way decision statement and is used in conjunction with an expression
  • 10. SIMPLE IF STATEMENT syntax :if(expression) { statement 1; statement 2; . True statement N; } statement-x; Note : If expression is true than the set of statements will be executed after that statement-x will also be executed. Otherwise, the set of statements will be skipped and statements-x will be executed.
  • 11. Result of expression •Based on the True Non-Zero evaluation of the conditional expression the result will be as follow False Zero
  • 12. EXAMPLE void main() { int i=5; if(i==5) { printf(“You are inside the if true block”); printf(“nvalue of i is equal to 5”); } printf(“nYou are outside the if block”); } output : You are inside the if true block value of i is equal to 5 You are outside the if block
  • 13. EXAMPLE void main() { int i=-5; if(i==5) { printf(“You are inside the if true block”); printf(“nvalue of i is equal to 5”); } printf(“nYou are outside the if block”); } output : You are outside the if block
  • 14. IF-ELSE STATEMENT SYNTAX if (expression) { statement 1; True statement 2; . . statement N; } else { statement 1; statement 2; . False . statement N; }
  • 15. IF-ELSE STATEMENT SYNTAX The if selection structure is often written as: if ( this logical expression is true ) no semi-colon! statement ; And, the if / else selection structure is often written as: if ( this logical expression is true ) statement ; else statement ;
  • 16. A VERY SIMPLE PROGRAM: #include <stdio.h> int main ( ) { int a = 1, b = 2, c ; if (a > b) { c = a; } else { c = b; } }
  • 17. A VERY SIMPLE PROGRAM: #include <stdio.h> int main ( ) { int a = 1, b = 2, c ; if (a > b) c = a; else c = b; }
  • 18. IF…ELSE IF…ELSE STATEMENT •To perform multi-path decisions •It is collection of if statement with association of else statement
  • 19. IF…ELSE IF…ELSE STATEMENT - SYNTAX if(expression1) { statement 1; } else if(expression2) { statement 2; } else if(expression3) { statement 3; } else { statement 4; //Also known as default statement }
  • 20. IF…ELSE IF…ELSE STATEMENT •The structure is also known as else if ladder •The conditions are evaluated from top of the ladder to downwards •if the expression1 evaluates to true than all the statements in this block will executed •Execution pointer will jump to the statement immediately after the closing curly braces •If all the given conditions evaluates to false than all the statements in else block will be executed •Else block is also known as default statement
  • 21. IF…ELSE IF…ELSE STATEMENT - EXAMPLE void main() { int num; num=4; if(num>1) { printf(“It is positive value”); } else if(num<1) { printf(“It is negative value”); } else { printf(“It is zero value”): } getch(); }
  • 22. EXAMPLE •WAP to accept marks for 5 subjects from the user, calculate total and percentage and find the result as per the following criteria Criteria Result Greater than or equal to 70 Distinction Between 60-70 First Class Between 50-60 Second Class Between 40-50 Pass Class Less than 40 Fail
  • 23. EXAMPLE Calculate the comission of a salesman considering three regions X,Y and Z depending on the sales amount as follow Area Code Sales Amount Comission X <1000 10% <5000 12% >=5000 15% Y <1500 10% <7000 12% >=7000 15% Z <1200 10% <6500 12% >=6500 15%
  • 24. EXAMPLE •Big Bazzar gives festival discount on purchase of their products in the following percentages i.If purchase amount < 1000 than 5% discount ii.If purchase amount >=1000 than but <3000 then 10% discount iii.If purchase amount >=3000 but <5000 then 12% discount iv.If purchase amount > 5000 then 15% discount

Editor's Notes

  1. Instructor: There are multiple forms the structure may take. It is important that students understand the logic they are creating both when they nest if/else structures and when using a large if/else if/else structure. Creating a flowchart prior to programming these section of code typically aids this process. Narrator: A simple if() structure, also known as a single-selection structure, either selects or ignores a single action. The if/else structure, also called a double-selection structure, allows the program to select two different actions, based on a true or false result. Nested if/else structures can test for multiple cases by placing additional if/else structures inside other if/else structures. *
  2. Instructor: These structures are valid only for processing single statements. The statement after the if() will ONLY be processed if the expression is TRUE. The statement after the else will ONLY be processed if the above if() statement evaluated to FALSE (it is skipped if the if() portion is true). If() can also be used by itself (no else is required after an if statement). Else CANNOT be used by itself. It must always be preceded by an if statement. Students may relate to the analogy of driving down the highway one direction and deciding which exit to take. You can only take one exit from the highway to get to the location you wish so the conditions (road signs) must be true for the correct exit. The location you wish to go to (the variable) will determine which exit you take. If you get to the end of the highway (none of the previous exits were the correct one) then you have to take the final exit (the else statement). Narrator: The syntax of the if/else selection structures are shown here. For the if selection structure, the single statement will be executed ONLY if the logical expression given as an argument is true. For the if/else selection structure, the single statement again after the if selection will be executed ONLY if the logical expression given as an argument is true. Otherwise in this case it will complete the statement given after the else portion of the structure. This can be likened to a fork in the road in which one path must be taken. *
  3. * Instructor: This shows a more common way of writing code so it is easier for a programmer to read later. The only difference from the last description is the statements are now on their own lines. It is very important to not insert a semicolon where shown or the program will behave unexpectedly.
  4. *