Calculate Percentage of Marks in C

Percentage is calculated by dividing the obtained total by the maximum possible total and multiplying by 100. Keep both values in floating-point form when a fractional percentage is possible.

Percentage from Total Marks Top ↑

#include <stdio.h>

int main(void) {
    double obtained = 423.0;
    double maximum = 500.0;

    double percentage = obtained / maximum * 100.0;

    printf("Percentage = %.2f%%\n", percentage);
    return 0;
}

Percentage from Five Subjects Top ↑

#include <stdio.h>

int main(void) {
    double marks[5];
    double total = 0.0;

    printf("Enter marks for five subjects: ");

    for (size_t i = 0; i < 5; i++) {
        if (scanf("%lf", &marks[i]) != 1 ||
            marks[i] < 0.0 ||
            marks[i] > 100.0) {
            printf("Each mark must be from 0 to 100.\n");
            return 1;
        }

        total += marks[i];
    }

    double percentage = total / 5.0;

    printf("Total = %.2f\n", total);
    printf("Percentage = %.2f%%\n", percentage);

    return 0;
}

Percentage and Grade Together Top ↑

if (percentage >= 80.0) {
    printf("Grade A\n");
} else if (percentage >= 60.0) {
    printf("Grade B\n");
} else if (percentage >= 40.0) {
    printf("Grade C\n");
} else {
    printf("Fail\n");
}

See the full grade program and division classification.





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



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