WAP to enter a marks in any subject and print the equivalent grade in C

Q. Write a program that asks student to enter his/her mark in any subject and print the equivalent grade. Your program should display "Invalid Input!", if the mark entered is less than 0 or more than 100. (2019, 3(a)- 8 Marks)












==> Code goes like this: 

#include<stdio.h>
int main()
{
    float marks;
    printf("\n Enter marks(in %) : ");
    scanf("%f",&marks);
    if(marks>=80 && marks<=100)
    {
        printf("\n A Grade");
    }
    else if(marks>=60 && marks<=79)
    {
        printf("\n B Grade");
    }
    else if(marks>=50 && marks <=59)
    {
        printf("\n C Grade");
    }
    else if(marks>=40 && marks<=49)
    {
        printf("\n D Grade");
    }
    else if(marks>=0 && marks<=39)
    {
        printf("\n E Grade");
    }
    else
    {
        printf("\n Invalid input");
    }
    return 0;
}
 

Output:













Output1:












I have used Dev CPP to compile this program.
If you are using Turbo C++ IDE, then use conio.h in link section after stdio.h
and use getch(); to hold the output screen, just before the end of main function.
If you have any confusion regarding the program, please, comment below.
Happy Coding !
Thank you
Share on Google Plus

About Nepali Xoro

Interested in Information Technology, Spreading Knowledge for Nepalease IT Students."Loves Traveling", Listen Music and Surfing web.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment