Thursday, March 3, 2016

Grade Generation or use of else-if statement in C

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
#include<stdio.h>               //preprocessor , header library file included.

main()                  //main funtion starts.
{
 int marks;                //variable taken  defining datatype
 
 printf("Enter your obtained marks:\t");         //a message to the user regarding the program
 scanf("%d",&marks);              //input taken from user.
                    
  if(marks<=100){              //if starts from here with a condition
  if(marks>=80 && marks<=100) printf("A+\n");       //else ....if ladder starts from here.
   else if(marks>=70 && marks<=79) printf("A-\n");
    else if(marks>=60 && marks<=69) printf("B+\n");
     else if(marks>=50 && marks<=59) printf("C+\n");
      else if(marks>=45 && marks<=49) printf("D\n");
       else if(marks>=0 && marks<=40) printf("F\n");   //else if ladder ends here.
  }                
  else
  printf("Sorry the inputed marks is greater than 100.\n");   //the default message printed.
         
}                   //program ends here.

No comments:

Post a Comment

Thank you for commenting. Please wait for response :)