Nested If Else Statement Example With Program

Explain Nested If Else Statement Example With The Program
\\ If you have any query or questions on my post, then please comment below //

Nested If Else: 
In my previous post you read what is nested if else statement. Now I am gonna tell you nested if else statement with examples:

Program: Write a program to find the value of y.




Solution: 
-------------------------------------------------------------
#inlcude<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
  int x, n, y;
 printf("Enter the value of n and x");
 scanf("%d%d", &n, &x);
    if(n == 1)
       {
         y =1+x;
         printf("%d",y);
       } 
    else
      {
           if(n == 2)
               {
                 y=1+(x/n);
                 printf("%d",y);
                }
           else
              {
                  if(n == 3)
                     {
                        y= 1+pow(x,n);
                        printf("%d",y); 
                      } 
                  else
                      {
                        y=1+(n*x);
                        printf("%d",y); 
                       }
              }
       }
getch();

---------------------------------------------------------------------

Program: Write a program to enter the temperature and print the following message according to the given temperature.
1. temp<=0                        "Its very very cold".
2. 0 < temp < 0                  "Its cold".
3. 10 < temp < =20            "Its cool out".
4.  20 < temp < =30           "Its warm".
5.  temp>30                        "Its hot".
Solution:
-------------------------------------------------------------------------------
#inlcude<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
  float temp;
  clrscr();
  printf("Enter The Temperature");
  scanf("%f",&temp);
  if(temp<=0)
     {
      printf("Its very very cold");
      }
  else
     {
        if(temp>0 && temp<=10)
           {
            printf("Its cold");
           }
        else
           {
                if(temp>10 && temp < =20)
                  {
                   printf("Its cool out");
                  }
               else
                 {
                    if(temp<=30 && temp>20)
                         {
                            printf("Its warm");
                          }
                      else
                         { 
                             printf("Its hot");
                          }
                 }  
           }
getch();
     }
--------------------------------------------------------------------------

Program: Write a program to input three numbers and find the largest number among three.
Solution:
---------------------------------------------------------------------------
#include<stdio.h>
#include<conio.h>
void main()
{
   int a,b,c;
   clrscr();
   printf("Enter three number");
   scanf("%d%d%d", &a, &b, &c);
   if(a>b && a>c)
       {
        printf("A is largest");
        }
   else
        {
              if(b>a && b>c)
                 {
                  printf("B is largest");
                  }
                else
                   {
                  printf("C is largest");                   
                   }
         }
getch();
}
----------------------------------------------------------------------------

Program: Write a program to an input percentage of a student and on the basis of that grade is allowed.
1.  > = 80             E+ Grade
2. 70 - 79             E
3. 60 - 69             A+
4. 50 - 59             A
5. 40 - 49             B
6. <40                  Fail.

Program:
---------------------------------------------------------------------------------
#include<stdio.h>
#include<conio.h>
void main()
{
float percent;
printf("Enter the percentage");
scanf("%f", &percent);
    if(percent>=80)
       {
          printf("Grade is E+");
       }
     else
       {
           if(percent>=70 && percent<=79)
              {
                printf("Grade is E");
               }
            else
               {
                  if(percent>=60 && percent <=69)
                     {
                            printf("Grade is A+");
                      }
                  else
                     {
                          if(percent>=50 && percent <=59)
                                {
                                  printf("Grade is A");
                                 }
                           else
                                {
                                   if(percent>=40 && percent <=49)
                                       {
                                           printf("Grade is B");
                                        }
                                    else
                                         {
                                            printf("Fail");
                                          }
                                }
                     }
                }
       }
}
----------------------------------------------------------------------------
   

Click Here To Know How To Download Above Video Tutorials Or YouTube Videos Free


 Enter Your Email Id To Get Our Programming, Web Development, Video Tutorial, Job Updates In The Mail :

Labels: