What Is Nested If-Else Statement?

 What Is Nested If-Else Statement?

what is nested if else statement in c language

Hello Programmers,


Today we will discuss one more important clause of 'if statement'. Today we will discuss 'nested if-else' statement this is one more important clause in 'if statement'. In the last blog, we studied 'if-else' statement and today we will discuss one more statement that is 'nested if-else statement'.



Definition:


Nested 'if-else' statement is one more 'if-else' statement is called as nested 'if-else' control statement.

Syntax:-


if(Test Condition1)
{
    if(Test Condition2)
        {
        statement-1;
      }
    else
      { 
        statement-2;
      }
else
{
    if(Test Condition3)
     {
            statement-3;
      }
    else
     {
                statement-4;
        }
}

        
If Test Condition-1 is true then enter into inside 'if' condition and check Test Condition-2 if test condition-2 is true then statement-1 is executed otherwise statement-2 is executed. 

If Test Condition-1 is false then else statement is executed and inside the else statement it checks Test Condition-3 if it is true then statement-3 executed otherwise statement-4 is executed.



Program To Select And Print The Largest Of Three Float Number:


#include<stdio.h>

#include<conio.h>

int main()

{

    float a,b,c;

    printf("Enter Three Value ");

    scanf("%f%f%f",&a,&b,&c);

     printf("\n Largest Value is: ");

    if(a>b)

        {

            if(a>c)

          {

               printf("%f",a);

          }

        else

           {

                printf("%f",c);

            }

        else

          {

             if(b>c)

               {

                     printf("%f",b);

                }

               else

                {

                   printf("%f",c);

                }

          }

getch();

}


Output:


Enter Three values: 9.12  5.34  3.87

Largest Value is: 9.12



Sharing Is Caring...

Comments :

Post a Comment