Nested-if-else-statement .

In this session i have discussed nested if-else statement in C .


NESTED-IF-ELSE-Statement :

C allows the nesting of if-else statement means you can use the if-else with in if statement It is also decision making and branching statement .

Nested-If-Else-statement-syntax :

CSharp Nested if else image

Example : Write a program check the userid or password using nested if else statement .

    #includ<stdio.h> 
    int main()
    {  
          int uid = 10, pwd = 20;
          if (uid == 10)
          {
               if (pwd == 20)
               {
                    printf("Login successfull");
               }
               else
               {

                   printf("Invalid password");
               }
          }
          else
          {
                printf("Invalid UserID");
          }

          printf("\nThanks");
          return 0;
    }
    
    OUTPUT : Login successfull
             Thanks
    


Example : Write a program check the maximum number among three number using nested if-else statement .

    #includ<stdio.h> 
    int main()
    {  
            int x=20 ,y=10,z=50;
            if(x>y)
            {
                if(x>z)
                {
                    printf("%d",x);
                }
                else
                {
                    printf("%d",z);
                }
                
            }
            else
            {
                if(y>z)
                {
                    printf("%d",y);
                }
                else
                {
                    printf("%d",z);
                }
                
            }
            printf("\nThanks");
            return 0;
    }
    
    OUTPUT : 50
             Thanks
    


Welcome to AndroidATPoint.

back image                     next image