SlideShare a Scribd company logo
C Programming - Decision & Loop
           Control

 Organized By: Vinay Arora
                Assistant Professor, CSED
                Thapar University, Patiala
Decision Control

   The if statement



   The if-else statement



   The conditional operators




                               Vinay Arora
                                  CSED
Forms of if




              Vinay Arora
                 CSED
Forms of if (contd.)




                  Vinay Arora
                     CSED
Relational Operator




                 Vinay Arora
                    CSED
Demonstrating - If




                 Vinay Arora
                    CSED
Flowchart




            Vinay Arora
               CSED
Demonstrating - If




                 Vinay Arora
                    CSED
Flowchart




            Vinay Arora
               CSED
Expression in Conditional Part




                 Vinay Arora
                    CSED
Multiple statements within if




                  Vinay Arora
                     CSED
Demonstrating If - Else




                 Vinay Arora
                    CSED
Flowchart If-Else




                    Vinay Arora
                       CSED
Logical Operators with If-Else




                 Vinay Arora
                    CSED
Logical Operators with If-Else




                 Vinay Arora
                    CSED
Else-if ladder




                 Vinay Arora
                    CSED
Logical Operators with If-Else




                 Vinay Arora
                    CSED
Smallest amongst 3 nos.




                 Vinay Arora
                    CSED
Smallest amongst 3 nos.




                 Vinay Arora
                    CSED
Program using Logical OR, elseif




                 Vinay Arora
                    CSED
Calculate Salary as per following table




                    Vinay Arora
                       CSED
&& - Logical AND
  C allows usage of three logical operators, namely, &&, || and !



  These are to be read as ‘AND’ ‘OR’ and ‘NOT’ respectively.



  Don’t use the single symbol | and &. These single symbols also have a
  meaning.



  The first two operators, && and ||, allow two or more conditions to be
  combined in an if statement.

                                 Vinay Arora
                                    CSED
&& - Logical AND (C Program)




               Vinay Arora
                  CSED
Vinay Arora
   CSED
Vinay Arora
   CSED
| | - Logical OR (C Program)




                 Vinay Arora
                    CSED
Vinay Arora
   CSED
Vinay Arora
   CSED
! - Logical NOT
  This operator reverses the result of the expression it operates on.

  For example, if the expression evaluates to a non-zero value, then
  applying ! operator to it results into a 0.

  Vice versa, if the expression evaluates to zero then on applying !
  operator to it makes it 1, a non-zero value.




                                  Vinay Arora
                                     CSED
! - Logical NOT (C Program)




               Vinay Arora
                  CSED
Vinay Arora
   CSED
Vinay Arora
   CSED
&&, ||, ! Operator




                 Vinay Arora
                    CSED
? : - Conditional Operator
  The conditional operators ? and : are sometimes called Ternary
  Operators since they take three arguments.

  They form a kind of foreshortened if-then-else.

  Their general form is, expression 1 ? expression 2 : expression 3

  If expression 1 is true (that is, if its value is non-zero), then the value
  returned will be expression 2, otherwise the value returned will be
  expression 3.




                                   Vinay Arora
                                      CSED
Conditional Operator (C Program)




                Vinay Arora
                   CSED
Vinay Arora
   CSED
Vinay Arora
   CSED
goto Statement

   goto is used to switch the control flow.

   In a difficult programming situation it seems so easy to use a goto to
   take the control.

   In most of the scenarios use of goto is depreciated.

   goto can be replaced by if-else, switch, for.




                                   Vinay Arora
                                      CSED
goto Statement - Program




                Vinay Arora
                   CSED
Vinay Arora
   CSED
Vinay Arora
   CSED
switch Statement
   The control statement that allows us to make a decision from the number
   of choices is called a switch.




  The integer expression following the keyword switch is any C expression that
  will yield an integer value.


                                    Vinay Arora
                                       CSED
switch Statement - Flowchart




                 Vinay Arora
                    CSED
switch Statement - Program




                Vinay Arora
                   CSED
Vinay Arora
   CSED
Vinay Arora
   CSED
Loops
  Repetitive instructions is done through a Loop control instruction.

  This involves repeating some portion of the program either a
  specified number of times or until a particular condition is being
  satisfied.

  There are three methods by way of which we can repeat a part of a
  program. They are:

  (a) Using a while statement
  (b) Using a do-while statement
  (c) Using a for statement

                               Vinay Arora
                                  CSED
while Loop - Flowchart




                Vinay Arora
                   CSED
while Loop – general form




                 Vinay Arora
                    CSED
while Loop – forms of conditions




                 Vinay Arora
                    CSED
while Loop – C Program




                Vinay Arora
                   CSED
Vinay Arora
   CSED
While Loop – Program 1
        //Program to demonstrate simple while loop
        #include<stdio.h>
        #include<conio.h>

         void main()
          {
           int i=1;
           clrscr();

           while (i<=10)
           {
            printf("%dn",i);
            i=i+1;
           }
          getch();
         }

                                Vinay Arora
                                   CSED
Output




         Vinay Arora
            CSED
While Loop – Program 2
  //Program to demonstrate simple while loop with decrement operator
  #include<stdio.h>
  #include<conio.h>

   void main()
    {
     int i=5;
     clrscr();

     while (i>=1)
     {
      printf("%dn",i);
      i=i-1;
     }
    getch();
   }

                                Vinay Arora
                                   CSED
Output




         Vinay Arora
            CSED
While Loop – Program 3
  /* Program to demonstrate simple while loop taking incremental value
     as float */
  #include<stdio.h>
  #include<conio.h>

   void main()
    {
     float i=10.0;
     clrscr();

     while (i<=10.5)
     {
      printf("nCivil Engineering at Thapar");
      i=i+.1;
     }
    getch();
   }
                                  Vinay Arora
                                     CSED
Output




         Vinay Arora
            CSED
While Loop – Program 4
  //Demonstrating simple while loop with integer value out of range
  #include<stdio.h>
  #include<conio.h>

  void main()
   {
    int i=1;
    clrscr();

     while (i<=32767)
     {
      printf("%dn",i);
      i=i+1;
     }
    getch();
   }

                                  Vinay Arora
                                     CSED
Output – Infinite Loop




                 Vinay Arora
                    CSED
While Loop – Program 5
     //Program to demonstrate simple while loop
     #include<stdio.h>
     #include<conio.h>

      void main()
       {
        int i=1;
        clrscr();

        while (i<=10);
        {
         printf("%dn",i);
         i=i+1;
        }
       getch();
      }

                             Vinay Arora
                                CSED
Output




         Vinay Arora
            CSED
While Loop – Program 6
  //Program to demonstrate post increment operator in while loop
  #include<stdio.h>
  #include<conio.h>

  void main()
   {
    int i=1;
    clrscr();

     while (i<=10)
     {
      printf("%dn",i);
      i=i++;
     }
    getch();
   }

                                  Vinay Arora
                                     CSED
Output




         Vinay Arora
            CSED
While Loop – Program 7
 //Program to demonstrate compound assignment operator within while loop
 #include<stdio.h>
 #include<conio.h>

 void main()
  {
   int i=1;
   clrscr();

    while (i<=5)
    {
     printf("%dn",i);
     i+=1;
    }
   getch();
  }

                                  Vinay Arora
                                     CSED
Output




         Vinay Arora
            CSED
While Loop – Program 8
  //Program to demonstrate post increment operator with while loop
  #include<stdio.h>
  #include<conio.h>

  void main()
   {
    int i=0;
    clrscr();

    while (i++ < 5)
    {
     printf("%dn",i);

     }
    getch();
   }

                                  Vinay Arora
                                     CSED
Output




         Vinay Arora
            CSED
While Loop – Program 9
 //Program to find out even numbers between 1-10
 #include<stdio.h>
 #include<conio.h>

 void main()
  {
   int i=1;
   clrscr();

    while (i<=10)
    {
     if (i%2==0)
           printf("%dn",i);
     i=i+1;
    }
   getch();
  }
                                 Vinay Arora
                                    CSED
Output




         Vinay Arora
            CSED
Do-while Loop




    While



                              Do while


                Vinay Arora
                   CSED
Do-while Loop – Program 10
       //Program to demonstrate DO-WHILE loop
       #include<stdio.h>
       #include<conio.h>

       void main()
        {
         int i=1;
         clrscr();

        /*
         while(i<1)
          {
           printf("hello i am at Thapar");
          }
        */

        do
        {
         printf("hello i am at Thapar");
        }
        while(i<1);

        getch();
        }


                                             Vinay Arora
                                                CSED
Output




         Vinay Arora
            CSED
Program Transformation




               Unary Post Increment
                    Operator



                 Vinay Arora
                    CSED
Program Transformation




                   Compound
              Assignment Operator



                 Vinay Arora
                    CSED
For Loop
  The for allows us to specify three things about a loop in a single line:




                                 Vinay Arora
                                    CSED
For Loop (Program-1)
        //Program to demonstrate simple For loop
        #include<stdio.h>
        #include<conio.h>

        void main()
         {
          int i;
          clrscr();

         for (i=1; i<=10; i=i+1)
          printf("%dn",i);

             getch();
         }



                             Vinay Arora
                                CSED
For Loop (Program-1 Output)




                  Vinay Arora
                     CSED
For Loop (Program-2)
         //Program to demonstrate simple For loop
         #include<stdio.h>
         #include<conio.h>

         void main()
          {
           int i;
           clrscr();

           for (i=1; i<=10;)
            {
             printf("%dn",i);
             i=i+1;
            }
            getch();
          }

                             Vinay Arora
                                CSED
For Loop (Program-2 Output)




                  Vinay Arora
                     CSED
For Loop (Program-3)
         //Program to demonstrate simple For loop
         //Print numbers from 1 to 5
         #include<stdio.h>
         #include<conio.h>

         void main()
          {
           int i=1;
           clrscr();

           for (;i<=5;i=i+1)
            {
             printf("%dn",i);
            }
            getch();
          }

                             Vinay Arora
                                CSED
For Loop (Program-3 Output)




                  Vinay Arora
                     CSED
For Loop (Program-4)
         //Program to demonstrate simple For loop
         #include<stdio.h>
         #include<conio.h>

         void main()
          {
           int i=1;
           clrscr();

           for (;i<=5;)
            {
             printf("%dn",i);
             i=i+1;
            }
            getch();
          }

                             Vinay Arora
                                CSED
For Loop (Program-4 Output)




                  Vinay Arora
                     CSED
For Loop (Program-5)
         //Program to demonstrate simple For loop
         #include<stdio.h>
         #include<conio.h>

         void main()
          {
           int i;
           clrscr();

           for (i=0;i++<5;)
            {
             printf("%dn",i);
            }
            getch();
          }

                             Vinay Arora
                                CSED
For Loop (Program-5 Output)




                  Vinay Arora
                     CSED
For Loop (Program-6)
        //Program to demonstrate simple For loop
        #include<stdio.h>
        #include<conio.h>

         void main()
          {
           int i;
           clrscr();

          for (i=0;++i<5;)
           {
            printf("%dn",i);
           }
           getch();
         }


                                Vinay Arora
                                   CSED
For Loop (Program-6 Output)




                  Vinay Arora
                     CSED
For Loop (Program-7)
        //Program to demonstrate NESTED For loop
        #include<stdio.h>
        #include<conio.h>

        void main()
         {
          int i,j;
          clrscr();

          for (i=1;i<=5;i=i+1)
           {
            printf("n");
            for (j=1;j<=i;j=j+1)
             {
              printf(" *");
             }
           }
           getch();
         }
                                   Vinay Arora
                                      CSED
For Loop (Program-7 Output)




                  Vinay Arora
                     CSED
Thnx…



  Vinay Arora
     CSED

More Related Content

What's hot

Important C program of Balagurusamy Book
Important C program of Balagurusamy BookImportant C program of Balagurusamy Book
Important C program of Balagurusamy Book
Abir Hossain
 
C programing Tutorial
C programing TutorialC programing Tutorial
C programing Tutorial
Mahira Banu
 
CP Handout#6
CP Handout#6CP Handout#6
CP Handout#6
trupti1976
 
C fundamentals
C fundamentalsC fundamentals
C programming Workshop
C programming WorkshopC programming Workshop
C programming Workshop
neosphere
 
C Programming Unit-1
C Programming Unit-1C Programming Unit-1
C Programming Unit-1
Vikram Nandini
 
Decision statements in c language
Decision statements in c languageDecision statements in c language
Decision statements in c language
tanmaymodi4
 
C Programming Unit-2
C Programming Unit-2C Programming Unit-2
C Programming Unit-2
Vikram Nandini
 
Chowtodoprogram solutions
Chowtodoprogram solutionsChowtodoprogram solutions
Chowtodoprogram solutions
Musa Gürbüz
 
C operators
C operatorsC operators
C operators
srmohan06
 
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
 
Programming fundamental 02
Programming fundamental 02Programming fundamental 02
Programming fundamental 02
Suhail Akraam
 
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
 
Storage classes in c language
Storage classes in c languageStorage classes in c language
Storage classes in c language
tanmaymodi4
 
1584503386 1st chap
1584503386 1st chap1584503386 1st chap
1584503386 1st chapthuhiendtk4
 
CP Handout#4
CP Handout#4CP Handout#4
CP Handout#4
trupti1976
 

What's hot (17)

Important C program of Balagurusamy Book
Important C program of Balagurusamy BookImportant C program of Balagurusamy Book
Important C program of Balagurusamy Book
 
C programing Tutorial
C programing TutorialC programing Tutorial
C programing Tutorial
 
CP Handout#6
CP Handout#6CP Handout#6
CP Handout#6
 
C fundamentals
C fundamentalsC fundamentals
C fundamentals
 
C programming Workshop
C programming WorkshopC programming Workshop
C programming Workshop
 
C Programming Unit-1
C Programming Unit-1C Programming Unit-1
C Programming Unit-1
 
Decision statements in c language
Decision statements in c languageDecision statements in c language
Decision statements in c language
 
Input And Output
 Input And Output Input And Output
Input And Output
 
C Programming Unit-2
C Programming Unit-2C Programming Unit-2
C Programming Unit-2
 
Chowtodoprogram solutions
Chowtodoprogram solutionsChowtodoprogram solutions
Chowtodoprogram solutions
 
C operators
C operatorsC operators
C operators
 
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’
 
Programming fundamental 02
Programming fundamental 02Programming fundamental 02
Programming fundamental 02
 
Decision making statements in C programming
Decision making statements in C programmingDecision making statements in C programming
Decision making statements in C programming
 
Storage classes in c language
Storage classes in c languageStorage classes in c language
Storage classes in c language
 
1584503386 1st chap
1584503386 1st chap1584503386 1st chap
1584503386 1st chap
 
CP Handout#4
CP Handout#4CP Handout#4
CP Handout#4
 

Viewers also liked

detailed information about Pointers in c language
detailed information about Pointers in c languagedetailed information about Pointers in c language
detailed information about Pointers in c language
gourav kottawar
 
Basic for Loop in C
Basic for Loop in CBasic for Loop in C
Basic for Loop in C
Rohit Soni
 
Memory allocation in c
Memory allocation in cMemory allocation in c
Memory allocation in c
Prabhu Govind
 
C program language tutorial for loop while loop do while loop
C program language tutorial for loop while loop do while loopC program language tutorial for loop while loop do while loop
C program language tutorial for loop while loop do while loop
Sourav Ganguly
 
Structure in C
Structure in CStructure in C
Structure in C
Kamal Acharya
 
C Pointers
C PointersC Pointers
C Pointers
omukhtar
 

Viewers also liked (6)

detailed information about Pointers in c language
detailed information about Pointers in c languagedetailed information about Pointers in c language
detailed information about Pointers in c language
 
Basic for Loop in C
Basic for Loop in CBasic for Loop in C
Basic for Loop in C
 
Memory allocation in c
Memory allocation in cMemory allocation in c
Memory allocation in c
 
C program language tutorial for loop while loop do while loop
C program language tutorial for loop while loop do while loopC program language tutorial for loop while loop do while loop
C program language tutorial for loop while loop do while loop
 
Structure in C
Structure in CStructure in C
Structure in C
 
C Pointers
C PointersC Pointers
C Pointers
 

Similar to C Prog. - Decision & Loop Controls

C and Data structure lab manual ECE (2).pdf
C and Data structure lab manual ECE (2).pdfC and Data structure lab manual ECE (2).pdf
C and Data structure lab manual ECE (2).pdf
janakim15
 
CP Handout#5
CP Handout#5CP Handout#5
CP Handout#5
trupti1976
 
Intro to Arduino Programming.pdf
Intro to Arduino Programming.pdfIntro to Arduino Programming.pdf
Intro to Arduino Programming.pdf
HimanshuDon1
 
Basic of Programming (Introduction to Programming)
Basic of Programming (Introduction to Programming)Basic of Programming (Introduction to Programming)
Basic of Programming (Introduction to Programming)
JohnNama
 
Object oriented programming system with C++
Object oriented programming system with C++Object oriented programming system with C++
Object oriented programming system with C++
msharshitha03s
 
C Prog. - ASCII Values, Break, Continue
C Prog. -  ASCII Values, Break, ContinueC Prog. -  ASCII Values, Break, Continue
C Prog. - ASCII Values, Break, Continuevinay arora
 
Logical Expressions in C/C++. Mistakes Made by Professionals
Logical Expressions in C/C++. Mistakes Made by ProfessionalsLogical Expressions in C/C++. Mistakes Made by Professionals
Logical Expressions in C/C++. Mistakes Made by Professionals
PVS-Studio
 
Fundamentals of computer programming by Dr. A. Charan Kumari
Fundamentals of computer programming by Dr. A. Charan KumariFundamentals of computer programming by Dr. A. Charan Kumari
Fundamentals of computer programming by Dr. A. Charan Kumari
THE NORTHCAP UNIVERSITY
 
the refernce of programming C notes ppt.pptx
the refernce of programming C notes ppt.pptxthe refernce of programming C notes ppt.pptx
the refernce of programming C notes ppt.pptx
AnkitaVerma776806
 
Programing for problem solving ( airline reservation system)
Programing for problem solving ( airline reservation system)Programing for problem solving ( airline reservation system)
Programing for problem solving ( airline reservation system)
Home
 
OWF12/PAUG Conf Days Pro guard optimizer and obfuscator for android, eric l...
OWF12/PAUG Conf Days Pro guard   optimizer and obfuscator for android, eric l...OWF12/PAUG Conf Days Pro guard   optimizer and obfuscator for android, eric l...
OWF12/PAUG Conf Days Pro guard optimizer and obfuscator for android, eric l...Paris Open Source Summit
 
C lecture 3 control statements slideshare
C lecture 3 control statements slideshareC lecture 3 control statements slideshare
C lecture 3 control statements slideshare
Gagan Deep
 
Write a program to check a given number is prime or not
Write a program to check a given number is prime or notWrite a program to check a given number is prime or not
Write a program to check a given number is prime or not
aluavi
 
OOPS using C++
OOPS using C++OOPS using C++
OOPS using C++
cpjcollege
 
20145-5SumII_CSC407_assign1.htmlCSC 407 Computer Systems II.docx
20145-5SumII_CSC407_assign1.htmlCSC 407 Computer Systems II.docx20145-5SumII_CSC407_assign1.htmlCSC 407 Computer Systems II.docx
20145-5SumII_CSC407_assign1.htmlCSC 407 Computer Systems II.docx
eugeniadean34240
 
12 lec 12 loop
12 lec 12 loop 12 lec 12 loop
12 lec 12 loop
kapil078
 
Rhino script 101 creativity
Rhino script 101 creativityRhino script 101 creativity
Rhino script 101 creativityR. Sosa
 
C programming language tutorial
C programming language tutorial C programming language tutorial
C programming language tutorial
javaTpoint s
 
Control structure of c
Control structure of cControl structure of c
Control structure of c
Komal Kotak
 

Similar to C Prog. - Decision & Loop Controls (20)

C and Data structure lab manual ECE (2).pdf
C and Data structure lab manual ECE (2).pdfC and Data structure lab manual ECE (2).pdf
C and Data structure lab manual ECE (2).pdf
 
CP Handout#5
CP Handout#5CP Handout#5
CP Handout#5
 
Intro to Arduino Programming.pdf
Intro to Arduino Programming.pdfIntro to Arduino Programming.pdf
Intro to Arduino Programming.pdf
 
Basic of Programming (Introduction to Programming)
Basic of Programming (Introduction to Programming)Basic of Programming (Introduction to Programming)
Basic of Programming (Introduction to Programming)
 
Object oriented programming system with C++
Object oriented programming system with C++Object oriented programming system with C++
Object oriented programming system with C++
 
C Prog. - ASCII Values, Break, Continue
C Prog. -  ASCII Values, Break, ContinueC Prog. -  ASCII Values, Break, Continue
C Prog. - ASCII Values, Break, Continue
 
Logical Expressions in C/C++. Mistakes Made by Professionals
Logical Expressions in C/C++. Mistakes Made by ProfessionalsLogical Expressions in C/C++. Mistakes Made by Professionals
Logical Expressions in C/C++. Mistakes Made by Professionals
 
Elements of programming
Elements of programmingElements of programming
Elements of programming
 
Fundamentals of computer programming by Dr. A. Charan Kumari
Fundamentals of computer programming by Dr. A. Charan KumariFundamentals of computer programming by Dr. A. Charan Kumari
Fundamentals of computer programming by Dr. A. Charan Kumari
 
the refernce of programming C notes ppt.pptx
the refernce of programming C notes ppt.pptxthe refernce of programming C notes ppt.pptx
the refernce of programming C notes ppt.pptx
 
Programing for problem solving ( airline reservation system)
Programing for problem solving ( airline reservation system)Programing for problem solving ( airline reservation system)
Programing for problem solving ( airline reservation system)
 
OWF12/PAUG Conf Days Pro guard optimizer and obfuscator for android, eric l...
OWF12/PAUG Conf Days Pro guard   optimizer and obfuscator for android, eric l...OWF12/PAUG Conf Days Pro guard   optimizer and obfuscator for android, eric l...
OWF12/PAUG Conf Days Pro guard optimizer and obfuscator for android, eric l...
 
C lecture 3 control statements slideshare
C lecture 3 control statements slideshareC lecture 3 control statements slideshare
C lecture 3 control statements slideshare
 
Write a program to check a given number is prime or not
Write a program to check a given number is prime or notWrite a program to check a given number is prime or not
Write a program to check a given number is prime or not
 
OOPS using C++
OOPS using C++OOPS using C++
OOPS using C++
 
20145-5SumII_CSC407_assign1.htmlCSC 407 Computer Systems II.docx
20145-5SumII_CSC407_assign1.htmlCSC 407 Computer Systems II.docx20145-5SumII_CSC407_assign1.htmlCSC 407 Computer Systems II.docx
20145-5SumII_CSC407_assign1.htmlCSC 407 Computer Systems II.docx
 
12 lec 12 loop
12 lec 12 loop 12 lec 12 loop
12 lec 12 loop
 
Rhino script 101 creativity
Rhino script 101 creativityRhino script 101 creativity
Rhino script 101 creativity
 
C programming language tutorial
C programming language tutorial C programming language tutorial
C programming language tutorial
 
Control structure of c
Control structure of cControl structure of c
Control structure of c
 

More from vinay arora

Search engine and web crawler
Search engine and web crawlerSearch engine and web crawler
Search engine and web crawler
vinay arora
 
Use case diagram (airport)
Use case diagram (airport)Use case diagram (airport)
Use case diagram (airport)
vinay arora
 
Use case diagram
Use case diagramUse case diagram
Use case diagram
vinay arora
 
Lab exercise questions (AD & CD)
Lab exercise questions (AD & CD)Lab exercise questions (AD & CD)
Lab exercise questions (AD & CD)
vinay arora
 
SEM - UML (1st case study)
SEM - UML (1st case study)SEM - UML (1st case study)
SEM - UML (1st case study)
vinay arora
 
6 java - loop
6  java - loop6  java - loop
6 java - loop
vinay arora
 
4 java - decision
4  java - decision4  java - decision
4 java - decision
vinay arora
 
3 java - variable type
3  java - variable type3  java - variable type
3 java - variable type
vinay arora
 
2 java - operators
2  java - operators2  java - operators
2 java - operators
vinay arora
 
1 java - data type
1  java - data type1  java - data type
1 java - data type
vinay arora
 
Uta005 lecture3
Uta005 lecture3Uta005 lecture3
Uta005 lecture3
vinay arora
 
Uta005 lecture1
Uta005 lecture1Uta005 lecture1
Uta005 lecture1
vinay arora
 
Uta005 lecture2
Uta005 lecture2Uta005 lecture2
Uta005 lecture2
vinay arora
 
Security & Protection
Security & ProtectionSecurity & Protection
Security & Protectionvinay arora
 
Process Synchronization
Process SynchronizationProcess Synchronization
Process Synchronizationvinay arora
 
CG - Output Primitives
CG - Output PrimitivesCG - Output Primitives
CG - Output Primitivesvinay arora
 
CG - Display Devices
CG - Display DevicesCG - Display Devices
CG - Display Devicesvinay arora
 
CG - Input Output Devices
CG - Input Output DevicesCG - Input Output Devices
CG - Input Output Devicesvinay arora
 
CG - Introduction to Computer Graphics
CG - Introduction to Computer GraphicsCG - Introduction to Computer Graphics
CG - Introduction to Computer Graphicsvinay arora
 
C Prog. - Strings (Updated)
C Prog. - Strings (Updated)C Prog. - Strings (Updated)
C Prog. - Strings (Updated)vinay arora
 

More from vinay arora (20)

Search engine and web crawler
Search engine and web crawlerSearch engine and web crawler
Search engine and web crawler
 
Use case diagram (airport)
Use case diagram (airport)Use case diagram (airport)
Use case diagram (airport)
 
Use case diagram
Use case diagramUse case diagram
Use case diagram
 
Lab exercise questions (AD & CD)
Lab exercise questions (AD & CD)Lab exercise questions (AD & CD)
Lab exercise questions (AD & CD)
 
SEM - UML (1st case study)
SEM - UML (1st case study)SEM - UML (1st case study)
SEM - UML (1st case study)
 
6 java - loop
6  java - loop6  java - loop
6 java - loop
 
4 java - decision
4  java - decision4  java - decision
4 java - decision
 
3 java - variable type
3  java - variable type3  java - variable type
3 java - variable type
 
2 java - operators
2  java - operators2  java - operators
2 java - operators
 
1 java - data type
1  java - data type1  java - data type
1 java - data type
 
Uta005 lecture3
Uta005 lecture3Uta005 lecture3
Uta005 lecture3
 
Uta005 lecture1
Uta005 lecture1Uta005 lecture1
Uta005 lecture1
 
Uta005 lecture2
Uta005 lecture2Uta005 lecture2
Uta005 lecture2
 
Security & Protection
Security & ProtectionSecurity & Protection
Security & Protection
 
Process Synchronization
Process SynchronizationProcess Synchronization
Process Synchronization
 
CG - Output Primitives
CG - Output PrimitivesCG - Output Primitives
CG - Output Primitives
 
CG - Display Devices
CG - Display DevicesCG - Display Devices
CG - Display Devices
 
CG - Input Output Devices
CG - Input Output DevicesCG - Input Output Devices
CG - Input Output Devices
 
CG - Introduction to Computer Graphics
CG - Introduction to Computer GraphicsCG - Introduction to Computer Graphics
CG - Introduction to Computer Graphics
 
C Prog. - Strings (Updated)
C Prog. - Strings (Updated)C Prog. - Strings (Updated)
C Prog. - Strings (Updated)
 

Recently uploaded

Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Dr. Vinod Kumar Kanvaria
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
Scholarhat
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdfMASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
goswamiyash170123
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBCSTRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
kimdan468
 
Multithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race conditionMultithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race condition
Mohammed Sikander
 
Normal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of LabourNormal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of Labour
Wasim Ak
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 

Recently uploaded (20)

Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdfMASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBCSTRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
 
Multithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race conditionMultithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race condition
 
Normal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of LabourNormal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of Labour
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 

C Prog. - Decision & Loop Controls

  • 1. C Programming - Decision & Loop Control Organized By: Vinay Arora Assistant Professor, CSED Thapar University, Patiala
  • 2. Decision Control The if statement The if-else statement The conditional operators Vinay Arora CSED
  • 3. Forms of if Vinay Arora CSED
  • 4. Forms of if (contd.) Vinay Arora CSED
  • 5. Relational Operator Vinay Arora CSED
  • 6. Demonstrating - If Vinay Arora CSED
  • 7. Flowchart Vinay Arora CSED
  • 8. Demonstrating - If Vinay Arora CSED
  • 9. Flowchart Vinay Arora CSED
  • 10. Expression in Conditional Part Vinay Arora CSED
  • 11. Multiple statements within if Vinay Arora CSED
  • 12. Demonstrating If - Else Vinay Arora CSED
  • 13. Flowchart If-Else Vinay Arora CSED
  • 14. Logical Operators with If-Else Vinay Arora CSED
  • 15. Logical Operators with If-Else Vinay Arora CSED
  • 16. Else-if ladder Vinay Arora CSED
  • 17. Logical Operators with If-Else Vinay Arora CSED
  • 18. Smallest amongst 3 nos. Vinay Arora CSED
  • 19. Smallest amongst 3 nos. Vinay Arora CSED
  • 20. Program using Logical OR, elseif Vinay Arora CSED
  • 21. Calculate Salary as per following table Vinay Arora CSED
  • 22. && - Logical AND C allows usage of three logical operators, namely, &&, || and ! These are to be read as ‘AND’ ‘OR’ and ‘NOT’ respectively. Don’t use the single symbol | and &. These single symbols also have a meaning. The first two operators, && and ||, allow two or more conditions to be combined in an if statement. Vinay Arora CSED
  • 23. && - Logical AND (C Program) Vinay Arora CSED
  • 24. Vinay Arora CSED
  • 25. Vinay Arora CSED
  • 26. | | - Logical OR (C Program) Vinay Arora CSED
  • 27. Vinay Arora CSED
  • 28. Vinay Arora CSED
  • 29. ! - Logical NOT This operator reverses the result of the expression it operates on. For example, if the expression evaluates to a non-zero value, then applying ! operator to it results into a 0. Vice versa, if the expression evaluates to zero then on applying ! operator to it makes it 1, a non-zero value. Vinay Arora CSED
  • 30. ! - Logical NOT (C Program) Vinay Arora CSED
  • 31. Vinay Arora CSED
  • 32. Vinay Arora CSED
  • 33. &&, ||, ! Operator Vinay Arora CSED
  • 34. ? : - Conditional Operator The conditional operators ? and : are sometimes called Ternary Operators since they take three arguments. They form a kind of foreshortened if-then-else. Their general form is, expression 1 ? expression 2 : expression 3 If expression 1 is true (that is, if its value is non-zero), then the value returned will be expression 2, otherwise the value returned will be expression 3. Vinay Arora CSED
  • 35. Conditional Operator (C Program) Vinay Arora CSED
  • 36. Vinay Arora CSED
  • 37. Vinay Arora CSED
  • 38. goto Statement goto is used to switch the control flow. In a difficult programming situation it seems so easy to use a goto to take the control. In most of the scenarios use of goto is depreciated. goto can be replaced by if-else, switch, for. Vinay Arora CSED
  • 39. goto Statement - Program Vinay Arora CSED
  • 40. Vinay Arora CSED
  • 41. Vinay Arora CSED
  • 42. switch Statement The control statement that allows us to make a decision from the number of choices is called a switch. The integer expression following the keyword switch is any C expression that will yield an integer value. Vinay Arora CSED
  • 43. switch Statement - Flowchart Vinay Arora CSED
  • 44. switch Statement - Program Vinay Arora CSED
  • 45. Vinay Arora CSED
  • 46. Vinay Arora CSED
  • 47. Loops Repetitive instructions is done through a Loop control instruction. This involves repeating some portion of the program either a specified number of times or until a particular condition is being satisfied. There are three methods by way of which we can repeat a part of a program. They are: (a) Using a while statement (b) Using a do-while statement (c) Using a for statement Vinay Arora CSED
  • 48. while Loop - Flowchart Vinay Arora CSED
  • 49. while Loop – general form Vinay Arora CSED
  • 50. while Loop – forms of conditions Vinay Arora CSED
  • 51. while Loop – C Program Vinay Arora CSED
  • 52. Vinay Arora CSED
  • 53. While Loop – Program 1 //Program to demonstrate simple while loop #include<stdio.h> #include<conio.h> void main() { int i=1; clrscr(); while (i<=10) { printf("%dn",i); i=i+1; } getch(); } Vinay Arora CSED
  • 54. Output Vinay Arora CSED
  • 55. While Loop – Program 2 //Program to demonstrate simple while loop with decrement operator #include<stdio.h> #include<conio.h> void main() { int i=5; clrscr(); while (i>=1) { printf("%dn",i); i=i-1; } getch(); } Vinay Arora CSED
  • 56. Output Vinay Arora CSED
  • 57. While Loop – Program 3 /* Program to demonstrate simple while loop taking incremental value as float */ #include<stdio.h> #include<conio.h> void main() { float i=10.0; clrscr(); while (i<=10.5) { printf("nCivil Engineering at Thapar"); i=i+.1; } getch(); } Vinay Arora CSED
  • 58. Output Vinay Arora CSED
  • 59. While Loop – Program 4 //Demonstrating simple while loop with integer value out of range #include<stdio.h> #include<conio.h> void main() { int i=1; clrscr(); while (i<=32767) { printf("%dn",i); i=i+1; } getch(); } Vinay Arora CSED
  • 60. Output – Infinite Loop Vinay Arora CSED
  • 61. While Loop – Program 5 //Program to demonstrate simple while loop #include<stdio.h> #include<conio.h> void main() { int i=1; clrscr(); while (i<=10); { printf("%dn",i); i=i+1; } getch(); } Vinay Arora CSED
  • 62. Output Vinay Arora CSED
  • 63. While Loop – Program 6 //Program to demonstrate post increment operator in while loop #include<stdio.h> #include<conio.h> void main() { int i=1; clrscr(); while (i<=10) { printf("%dn",i); i=i++; } getch(); } Vinay Arora CSED
  • 64. Output Vinay Arora CSED
  • 65. While Loop – Program 7 //Program to demonstrate compound assignment operator within while loop #include<stdio.h> #include<conio.h> void main() { int i=1; clrscr(); while (i<=5) { printf("%dn",i); i+=1; } getch(); } Vinay Arora CSED
  • 66. Output Vinay Arora CSED
  • 67. While Loop – Program 8 //Program to demonstrate post increment operator with while loop #include<stdio.h> #include<conio.h> void main() { int i=0; clrscr(); while (i++ < 5) { printf("%dn",i); } getch(); } Vinay Arora CSED
  • 68. Output Vinay Arora CSED
  • 69. While Loop – Program 9 //Program to find out even numbers between 1-10 #include<stdio.h> #include<conio.h> void main() { int i=1; clrscr(); while (i<=10) { if (i%2==0) printf("%dn",i); i=i+1; } getch(); } Vinay Arora CSED
  • 70. Output Vinay Arora CSED
  • 71. Do-while Loop While Do while Vinay Arora CSED
  • 72. Do-while Loop – Program 10 //Program to demonstrate DO-WHILE loop #include<stdio.h> #include<conio.h> void main() { int i=1; clrscr(); /* while(i<1) { printf("hello i am at Thapar"); } */ do { printf("hello i am at Thapar"); } while(i<1); getch(); } Vinay Arora CSED
  • 73. Output Vinay Arora CSED
  • 74. Program Transformation Unary Post Increment Operator Vinay Arora CSED
  • 75. Program Transformation Compound Assignment Operator Vinay Arora CSED
  • 76. For Loop The for allows us to specify three things about a loop in a single line: Vinay Arora CSED
  • 77. For Loop (Program-1) //Program to demonstrate simple For loop #include<stdio.h> #include<conio.h> void main() { int i; clrscr(); for (i=1; i<=10; i=i+1) printf("%dn",i); getch(); } Vinay Arora CSED
  • 78. For Loop (Program-1 Output) Vinay Arora CSED
  • 79. For Loop (Program-2) //Program to demonstrate simple For loop #include<stdio.h> #include<conio.h> void main() { int i; clrscr(); for (i=1; i<=10;) { printf("%dn",i); i=i+1; } getch(); } Vinay Arora CSED
  • 80. For Loop (Program-2 Output) Vinay Arora CSED
  • 81. For Loop (Program-3) //Program to demonstrate simple For loop //Print numbers from 1 to 5 #include<stdio.h> #include<conio.h> void main() { int i=1; clrscr(); for (;i<=5;i=i+1) { printf("%dn",i); } getch(); } Vinay Arora CSED
  • 82. For Loop (Program-3 Output) Vinay Arora CSED
  • 83. For Loop (Program-4) //Program to demonstrate simple For loop #include<stdio.h> #include<conio.h> void main() { int i=1; clrscr(); for (;i<=5;) { printf("%dn",i); i=i+1; } getch(); } Vinay Arora CSED
  • 84. For Loop (Program-4 Output) Vinay Arora CSED
  • 85. For Loop (Program-5) //Program to demonstrate simple For loop #include<stdio.h> #include<conio.h> void main() { int i; clrscr(); for (i=0;i++<5;) { printf("%dn",i); } getch(); } Vinay Arora CSED
  • 86. For Loop (Program-5 Output) Vinay Arora CSED
  • 87. For Loop (Program-6) //Program to demonstrate simple For loop #include<stdio.h> #include<conio.h> void main() { int i; clrscr(); for (i=0;++i<5;) { printf("%dn",i); } getch(); } Vinay Arora CSED
  • 88. For Loop (Program-6 Output) Vinay Arora CSED
  • 89. For Loop (Program-7) //Program to demonstrate NESTED For loop #include<stdio.h> #include<conio.h> void main() { int i,j; clrscr(); for (i=1;i<=5;i=i+1) { printf("n"); for (j=1;j<=i;j=j+1) { printf(" *"); } } getch(); } Vinay Arora CSED
  • 90. For Loop (Program-7 Output) Vinay Arora CSED
  • 91. Thnx… Vinay Arora CSED