Translate

Saturday, April 25, 2020

The Nested if-else Statements :

The Nested if-else Statement

/*Control statement Nested if-else statement*/

  • The Nested if-else Statements :
In C language, we can have another if..else statement in the if block or the else block. This is called nested if-else.

The Syntax of Nested if-else:

if(condition 1)
{
    if(condition 2)
          statement A1;
       else
          statement A2;
}
else
{
   if(condition 3)
          statement B1;
        else
          statement B2;
}

The Example of Nested if-else:


#include<stdio.h>

#include<conio.h>
void main()
{
     int a, b, c;
     
    printf("enter value in a = ");
    scanf("%d",& a);
    printf("enter value in b = ");
    scanf("%d",& b);
    printf("enter value in c = ");
    scanf("%d",& c);
    
if(a<b)
     {
         if(a<c)
           printf("\na is smallest %d", a);
           else
            printf("\nc is smallest %d", c);
     }
     else
     {
         if(b<c)
            printf("\nb is smallest %d",b);
           else
            printf("\nc is smallest %d",c);
     }
    getch();
}

Output:







     



No comments:

Post a Comment

C program to make a calculator using the switch statement.

/*perform arithmetic calculation on integers in C language*/ #include<stdio.h> #include<conio.h> void main() {     char op;     ...