10.19.2012

Get Student Marks and Calculate Percentage & Division

Q. The marks obtained by a student in 5 different subjects are input through the keyboard.
The student gets a division as per the following rules:

Percentage above or equal to 60- 1st division
Percentage between 50 and 59- 2nd division
Percentage between 40 and 49- 3rd division
Percentage less then 40- Fail

Write a C program to calculate the division obtained by the student.

Ans.

/*c program for read 5 subject marks and calculate percentage & division of student*/
/*we assume total marks is 500*/
#include<stdio.h>
int main()
{
 float m1,m2,m3,m4,m5,avg,per; //m=marks
 printf("Enter 5 subject marks: ");
 scanf("%f %f %f %f %f",&m1,&m2,&m3,&m4,&m5);
 per = (m1+m2+m3+m4+m5)*100/500;
 printf("Student get %0.2f percentage. \n",per);
 if(per>=60)
   printf("1st Division");
 else if(per>=50 && per<=59)
   printf("2nd Division");
 else if(per>=40 && per<=49)
   printf("3rd Division");
 else if(per<40)
   printf("Fail");
 return 0;
}

The output of above program would be:


Output for calculate student percentage and division of C program
Figure: Screen shot for read student marks and calculate
percentage and find division C program

Related programs:

  1. Find student grade through structure

20 comments:

  1. Why are you using return 0 instead of getch() ???......What is the difference between these two??

    ReplyDelete
    Replies
    1. When we use int main() then we write return 0;
      when we use void main() then we write getch();

      Delete
  2. Why are you using return 0 instead of getch() ???......What is the difference between these two??

    ReplyDelete
    Replies
    1. @Gurpreet,

      In above program we used "int main()", i.e. main() is a integer type function so its return something so we use "return 0" (it is also indicating that this is last line program and program want to close.)

      In above program we not use " getch() " but we can.
      In software engineering it is says that when we close application/software then, there are comes a confirmation message some like as "Are you sure you want to exit", we say "yes" and exit.
      For using "getch()" C compiler require 2 enter for exit(one is display and second is exit) so there are not use getch().

      Delete
  3. grewal ......return 0 means " it is a return type means while u using int like datatypes .....u hve to put return 0"

    getch() it is use when u use headerfile conio.h ..........otherwise.......dont use that getch().......

    ReplyDelete
  4. If student enter marks more then 100 then there is no condition for that. how can we make condition in it

    ReplyDelete
    Replies
    1. Use this before per=(m1+m2+m3+m4+m5)/5;
      if((a<=100)&&(b<=100)&&(c<=100)&&(d<=100)&&(e<=100))
      {
      .....;
      .....;
      .....;
      }

      Delete
  5. Can u do this with switch case and use the percentage by taking marks/total marks method??

    ReplyDelete
  6. Write a pragram that inputs marks os ten students and prints the list of marks that are above average

    ReplyDelete
  7. help me out with this please Write a C program that prompts for students’ final grades in 5 units in a given class (the grades are integer values in the range 0-100). The program then displays the class grade average, the highest grade, and how many students in the class failed the course (a grade less than 40 is a failing grade). If a student fails in more than 2 subjects then a message “DISCONTINUATION” is displayed at the very end. An example running session looks as follow

    ReplyDelete
  8. 0111010000111011011100000111001001101101011100000111010000101000010111000010011000100011001100000011001100111001001110110110100001100001011000110110101101100101011001000101110000100110001000110011000000110011001110010011101100101001001001100110110001110100001110110010111101110011011000110111001001101001011100000111010000100110011001110111010000111011

    ReplyDelete
  9. if student gets less than 20 marks ( ie failed in one subject than ) what ?? this prgrm jst add all subject marks and shows its division !!

    ReplyDelete
  10. how to do with arrays...
    please answer with the code

    ReplyDelete
  11. i need total marks ,average, and percentage of student based on no. of subjects by user .
    help !!

    ReplyDelete
  12. how to exactly write this program using switch case

    ReplyDelete
  13. How to exactly write this program using switch case

    ReplyDelete
  14. undeclared per


    hahaha.. check it.... he didn't create per variable,,. how can u use that variable with out declaring the variable.. am i correct...

    ReplyDelete
    Replies
    1. The variable 'per' had been declared as float.

      Delete