C Programming

Solved Example

Practice Questions

Exercise Question

Calculate grade of a student

Objective:

Enter 3 subject marks of a student, calculate the percentage, and find the grade as per the following rules. It is assumed that the maximum marks of each subject are 100.

  1. If percentage >= 85, then the grade will be S
  2. If the percentage is between 75-84.99, then the grade will be A
  3. If the percentage is between 65-74.99, then the grade will be B
  4. If the percentage is between 55-64.99, then the grade will be C
  5. If the percentage is between 50-54.99, then the grade will be D
  6. If the percentage is <50, then the grade will be F

Program / Solution:

#includestdio.h
int main() {
	int m1,m2,m3;
	float per;
	char gd;
	
	printf("Enter 3 subject marks: ");
	scanf("%d %d %d",&m1,&m2,&m3);
	
	per = (m1 + m2 + m3)/3.0f;
	
	if(per >= 85) {
		gd = 'S';	
	} else if(per >= 75) {
		gd = 'A';
	} else if(per >= 65) {
		gd = 'B';
	} else if(per >= 55) {
		gd = 'C';
	} else if(per >= 50) {
		gd = 'D';
	} else {
		gd = 'F';
	}
	
	printf("Percentage = %.2f\nGrade = %c",per,gd);
	return 0;
	
}

Sample Output:

Enter 3 subject marks: 85 74 68
Percentage = 75.67
Grade = A

More Progarms of Decision Making in C

Calculate profit or loss

Check a number is even or odd

Check a number is positive or negative

Check a year is leap year or not

Find the first day of year

Find the youngest person

Absolute value of a number

Find area of rectangle is greater than perimeter

Check the points are co-linear or not

Check a point is inside,outside or on the circle

Check the axis of a point

Identify a character is alphabet, digit and more

Check the insurance eligibility and calculate premium

Calculate the library penalty charges