Percentage of Mark

the program below indicates the calculation of percentage.The user is asked to enter the marks of three subjects and then the percentage of total mark is calculated.

Average mark is also calculated by dividing total mark by 3.
#include<stdio.h>
#include<conio.h>

void main ()
{
	float m1,m2,m3;
	float per;
	float total;
	//clrscr();
	printf(" enter the marks of m1: ");
	scanf("%f", &m1);
	printf(" enter the marks of m2: ");
	scanf("%f", &m2);
	printf("enter the marks of m3: ");
	scanf("%f", &m3);
	total= m1+m2+m3;
	printf("the total mark is:  %.2f",total);
	per = (total/300)*100;
	avg = (total/3);
	printf(" the percentage mark is: %.2f", per);
	printf("\n the average mark  is: %.2f", avg);
	getch();
}

Calculating Grade

Read more on Grade
Based on the percentage of the student in three subjects , calculate the grade using this range.

80 or above A grade
60 or above B grade
40 or above C grade
39 or less Fail
#include<stdio.h>
#include<conio.h>

void main ()
{
	float m1,m2,m3;
	float per,avg;
	float total;
	
	printf(" enter the marks of m1 ");
	scanf("%f", &m1);
	printf(" enter the marks of m2 ");
	scanf("%f", &m2);
	printf("enter the marks of m3 ");
	scanf("%f", &m3);
	total= m1+m2+m3;
	printf("\n the total mark is %.2f ",total);
	per = (total/300)*100;
	avg = (total/3);
	printf("\n the percentage mark is : %.2f ", per);
	printf("\n the average mark  is: %.2f", avg);
	
	///// Grade calculation //
	if(per>=80) printf("\n Grade : A");
	else if(per>=60) printf("\n Grade : B");
	else if(per>=40) printf("\n Grade : C");
	else if(per<40) printf("\n Fail ");

	getch();
}

Example 1: Calculating Percentage of Marks

This example demonstrates how to calculate the percentage of marks obtained by a student in five subjects.

#include <stdio.h>

int main() {
    int m1, m2, m3, m4, m5;
    float percentage;
    
    printf("Enter marks for 5 subjects: ");
    scanf("%d %d %d %d %d", &m1, &m2, &m3, &m4, &m5);
    
    percentage = (m1 + m2 + m3 + m4 + m5) / 5.0;
    
    printf("Total Percentage = %.2f%%\n", percentage);
    
    return 0;
}
Output:
Enter marks for 5 subjects: 85 90 88 92 80
Total Percentage = 87.00%
---

Example 2: Categorizing Result Based on Percentage

This example categorizes the result into divisions based on the percentage calculated.

#include <stdio.h>

int main() {
    int m1, m2, m3, m4, m5;
    float percentage;
    
    printf("Enter marks for 5 subjects: ");
    scanf("%d %d %d %d %d", &m1, &m2, &m3, &m4, &m5);
    
    percentage = (m1 + m2 + m3 + m4 + m5) / 5.0;
    
    printf("Total Percentage = %.2f%%\n", percentage);
    
    if (percentage >= 60) {
        printf("First Division\n");
    } else if (percentage >= 50) {
        printf("Second Division\n");
    } else if (percentage >= 40) {
        printf("Third Division\n");
    } else {
        printf("Fail\n");
    }
    
    return 0;
}
Output:
Enter marks for 5 subjects: 70 65 60 75 80
Total Percentage = 70.00%
First Division


Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com



    Tahir khan

    09-11-2018

    i am a student. i want to become a software engineer this website is so helpful for me

    Post your comments , suggestion , error , requirements etc here




    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer