3/10/2016

C Program to Find Grade of a Student Using Switch Case

Write a C Program to Find Grade of a Student Using Switch Case, The user needs to enter the subject number and the program must return the Grade of the subject based on the number. If a student enters the number between 90 to 100 then our program must return the Grade A or Excellent, similarly for other ranges numbers. To get the help I have a Number to grade conversion table this may help you to find the proper logic and roadmap for our program to Calculate Grade Using Switch Statement in C.

Logic: Calculate Grade Using Switch Statement in C


Logic is very simple to Calculate Grade Using Switch Statement in C. Taking input from the user(Input should be between range given 0 to 100 Else program play with you), as we know that grading system so divides the Mark by 10 and put the case condition in program See the below Explanation Step by step for better understanding.

Number to Grade Conversion Table


Below is the number to Grade Conversion Table helps us to implements logic for C Program to Find Grade of a Student Using Switch Case.

Number to Grade Conversion Table

Switch Case Grade Program in C Explanation


So first divide the mark by 10 so we can get a reminder and as you can see in the program we use case 4 to case 10. So if the remainder is between 4 to 10 our case performs the particular grade operation and display the result See the Step By Step Example for each case may be in this grade(Switch Case Grade Program in C) problem.

Grade Program Example


Case 1: If the user is over smart then there is a condition that if the mark given by the user is greater than 100 then our program displays the message "Don't Be Smart Enter your Marks Between Limit" or else part of the program will be performed.

Enter the Mark:- 1000
Output:- Don't Be Smart Enter your Marks Between Limit.

Case 2: If the user is entering the marks between the 0 to 100 and then the particular grade portion will be executed and display the output in the Console screen.

Enter the Mark:- 95
Output:-Your Grade Is: A or Excellent

Now perform the same operation for Grade B, C, D, E, E-- and F. and write a C Program to Find Grade of a Student Using Switch Case.

Case 3: If Enter marks are not fulfilled the requirement of the case than the program will perform the default case.

Enter the Mark: 25
Output: You Grade Is: F or Fail

Required Knowledge: Format Specifiers, Switch Case.

Code: C Program to Find Grade of a Student Using Switch Case


#include<stdio.h>

int main()
{
   int marks;
   /*C Program to Find Grade of a Student Using Switch Case*/
   
   printf("\n-----------------------------------");
   printf("\nEnter The Marks Between 0 To 100:");
   
   printf("\nEnter The Mark: ");
   scanf("%d", &marks);
   
   if(marks>100)
   {
    /* Marks greater than 100 */
    printf("\nDon't Be Smart Enter your Marks Between Limit\n");
   }
   else
   {
   switch(marks/10)
   {
       case 10 :
       case 9 :
           /* Marks between 90-100 */
           printf("\n Your Grade is: A");
           break;
       case 8 :
            /* Marks between 80-89 */
           printf("\n Your Grade is: B" );
           break;
       case 7 :
           /* Marks between 70-79 */
           printf("\n Your Grade is: C" );
           break;
       case 6 :
           /* Marks between 60-69 */
           printf("\n Your Grade is: D" );
           break;
       case 5 :
            /* Marks between 50-59 */
           printf("\n Your Grade is: E" );
           break;
       case 4 :
           /* Marks between 40-59 */
           printf("\n Your Grade is: E--");
           break;
       default :
           /* Marks less than 40 */
           printf("\n You Grade is: F or Fail\n");
   }
 }

   getch();
   return 0;
}

New: Grade of a Student Using Switch Case Output


C Program to Find Grade of a Student Using Switch Case Output


Below you can find the source code output of C Program to Find Grade of a Student Using Switch Case.

Old: Switch Case Grade Program in C Output


Switch Case Grade Program in C Output

Similar to Grade of a Student


  1. C++ Program For Find A Grade Of Given Marks Using Switch Case
  2. Program to Store Student Information Using Structures and Pointer
  3. C Program To Store Information of Students Using Structure
  4. Program For Calculate Percentage Of 5 Subjects
  5. Java Program For Find A Grade Of Given Marks Using Switch Case
Previous Post
Next Post

post written by:

Hi, I’m Ghanendra Yadav, SEO Expert, Professional Blogger, Programmer, and UI Developer. Get a Solution of More Than 500+ Programming Problems, and Practice All Programs in C, C++, and Java Languages. Get a Competitive Website Solution also Ie. Hackerrank Solutions and Geeksforgeeks Solutions. If You Are Interested to Learn a C Programming Language and You Don't Have Experience in Any Programming, You Should Start with a C Programming Language, Read: List of Format Specifiers in C.
Follow Me

23 comments:

  1. whithout header file how can you your program work successfully

    ReplyDelete
  2. Ankit Mishra3/04/2017

    Latest IDE's does not need headers
    Like codeblocks
    Che k it

    ReplyDelete
  3. Instead of giving marks in input.. if I use grade in input like A and as output I want the marks limit 75-79. how can I found this type of output using codeblocks? plz help

    ReplyDelete
  4. The problem said clearly using switch-case. But your solution is using if-else?

    ReplyDelete
    Replies
    1. Thanks for Comment This is why cause many people think they are smart, and they put marks upto 10000 and infinite. So if you Enter marks in subject is greater than 100 then the program will print a message. This is Just for Fun You Can remove and Modified.

      Keep visiting Keep sharing

      Delete
  5. what is about 75 to 79 grade A- ?

    ReplyDelete
    Replies
    1. Hello,

      You can modify or you can add as many conditions you want. This a just an example of my College grading System so there is No grading between 75 to 79 but you can put a case for according to your Query or you can send me a Query through email so I can provide a Full solution with respect to your Query.

      Thanks For comment Keep visit keep share and Keep Healthy

      Delete
  6. Savage bro.. the first if condition statement which says to stay in limit

    ReplyDelete
    Replies
    1. Why this is savage bro. This is because you are not able to get a simple code. This is a very simple problem in CPP "Grade Of Given Marks Using Switch Case". The First "IF" statement say stay in the limit cause, programmer like you think and they are smart so they enter a marks value greater than 100 ie 2000. Now take a deep breath and think about what will the output or grade of a student in this way you are going to get 1000%.

      As we know that maximum marks you can get 100. This is the reason behind that the condition.

      I Think now your doubt in clear Good luck in your career. Thanks for visiting

      Delete
    2. I think you can change the message. am I right?

      Delete
    3. Yes We can change, this is just a msg you can also change. Thanks for your comment

      Delete
  7. Thanks for sharing a awesome and well explain program in C++, I am following your website in long time nd always found new and complete working code. Thanks for everything and showing your support to newbie or new programmers.

    ReplyDelete
    Replies
    1. Thanks for showing your support towards us. We try to make code well function and always try to solve and update a new as well as old code. Thanks again please share if you like our efforts.

      Delete
  8. I like the logic, If someone want to play with the program, he is not going to win. Thanks Bro. Happy Coding

    ReplyDelete
    Replies
    1. Same Thing I like about this website They have a Good knowledge about the Programming Problems

      Delete
  9. http://www.svvideshvidya.com/

    ReplyDelete
  10. Replies
    1. We all know this is a great website

      Delete
  11. This is a perfect solution of this problem

    ReplyDelete
  12. if 91-100=A & 81-90=B;then what is the code for this

    ReplyDelete