January 21, 2013

Decision making- Nested If else


decision making banner of nested if else statement

This statement can be used to select any one statement or a block which contains a set of instructions. Only that statement will execute which is true according to the data entered and rest other conditions will not executed.

FORMAT:
if(expression1)
Statement1;
else if(expression2)
statement2;
else if(expression3)
statement3;


/*Program to enter students name, roll number and its percentage and allot his division*/

#include<stdio.h>
#include<conio.h>
void main()
{
     int roll;
     char nm[40];
     float percent;
     printf("\n enter students name and roll number");
     scanf("%s%d",nm,&roll);  
     printf("\n enter percentage of the student");
     scanf("%f",&percent);     
     if(percent>=60.0)
     printf("\n student obtain first division");
     else if(percent>=50.0 || percent<60.0)
     printf("\n student obtain second division");
     else if(percent>=35.0 || percent<50.0)
     printf("\n student obtain third division");
     else
     printf("\n student is fail");
     getch();
     }


output of student division using nested if -else statements in C language



PRECAUTIONS

1. Enter accurate header files.
2. If you start any brackets then it’s necessary to close it.
3. Enter every statement with “;”.
4. Don’t use “;” after void main function.  

No comments:

Post a Comment