Q:

Write a C program to read marks and print percentage and division

0

C program to read marks and print percentage and division

Given (or input from the user) marks in 3 subjects and we have to calculate parentage and print the division.

Formula to get percentage: Total obtained marks *100/Grand total (total of maximum marks)

Division

Based on the percentage, we will print the division, if percentage is:

  1. Greater than or equal to 60, division will be "First"
  2. Greater than or equal to 50, division will be "Second"
  3. Greater than or equal to 40, division will be "Third"
  4. Less than it (we will not check any condition, it will be written in else), the result will be fail

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Consider the program:

#include<stdio.h>
int main()
{
	int science; 
	int math;
	int english;
	
	int total;
	float per;

	science = 50;
	math = 90;
	english = 40;
	//you can take input from user instead of these values

	//calculating total
	total= science + math + english;
	
	//calculating percentage
	per= (float) total*100/300;

	printf("Total Marks: %d\n",total);
	printf("Percentage is: %.2f\n",per);

	//checking division and printing
	if(per>=60)
	{
		printf("First division\n");
	}
	else if(per>=50)
	{
		printf("Second division");
	}
	else if(per>=40)
	{
		printf("Third division");
	}
	else
	{
		printf("Fail\n");
	}
	
	return 0;
}

Output

Total Marks: 180
Percentage is: 60.00
First division

This is a simple C program, if you are a beginner you will learn to calculate total, percentage and how to find division (example of multiple if else).

If liked or any issue with the program, feel free to leave your comment.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C programming Basic Input, Output, if else, Ternary Operator based Programs

Similar questions


need a help?


find thousands of online teachers now
Write a C program to calculate Gross Salary of an ... >>
<< Write a C program to check whether a person is eli...