Division from Marks in C

A division-classification program first calculates or accepts a percentage and then maps that value to ranges such as first, second or third division. Validate the percentage before classifying it.

Division from Percentage Top ↑

#include <stdio.h>

int main(void) {
    double percentage = 67.5;

    if (percentage < 0.0 || percentage > 100.0) {
        printf("Invalid percentage.\n");
    } else if (percentage >= 60.0) {
        printf("First Division\n");
    } else if (percentage >= 50.0) {
        printf("Second Division\n");
    } else if (percentage >= 40.0) {
        printf("Third Division\n");
    } else {
        printf("Fail\n");
    }

    return 0;
}

Read Percentage from the User Top ↑

#include <stdio.h>

int main(void) {
    double percentage;

    printf("Enter percentage: ");
    if (scanf("%lf", &percentage) != 1) {
        printf("Invalid input.\n");
        return 1;
    }

    if (percentage < 0.0 || percentage > 100.0) {
        printf("Percentage must be from 0 to 100.\n");
    } else if (percentage >= 60.0) {
        printf("First Division\n");
    } else if (percentage >= 50.0) {
        printf("Second Division\n");
    } else if (percentage >= 40.0) {
        printf("Third Division\n");
    } else {
        printf("Fail\n");
    }

    return 0;
}

Calculate the Percentage First Top ↑

#include <stdio.h>

int main(void) {
    double marks[] = {62, 71, 58, 69, 65};
    size_t count = sizeof marks / sizeof marks[0];
    double total = 0.0;

    for (size_t i = 0; i < count; i++) {
        total += marks[i];
    }

    double percentage = total / count;

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

    if (percentage >= 60.0) {
        printf("First Division\n");
    } else if (percentage >= 50.0) {
        printf("Second Division\n");
    } else if (percentage >= 40.0) {
        printf("Third Division\n");
    } else {
        printf("Fail\n");
    }

    return 0;
}
The division thresholds shown here are tutorial rules. Educational institutions may use different classification systems.

Preserved Example: Add a Distinction Category Top ↑

#include <stdio.h>

int main(void) {
    double percentage = 78.5;

    if (percentage >= 75.0) {
        printf("Distinction\n");
    } else if (percentage >= 60.0) {
        printf("First Division\n");
    } else if (percentage >= 50.0) {
        printf("Second Division\n");
    } else if (percentage >= 40.0) {
        printf("Third Division\n");
    } else {
        printf("Fail\n");
    }

    return 0;
}

Preserved Example: Calculate Percentage and Division with Functions Top ↑

#include <stdio.h>

 double calculate_percentage(const double marks[], size_t count) {
    double total = 0.0;
    for (size_t i = 0; i < count; i++) total += marks[i];
    return total / count;
}

void print_division(double percentage) {
    if (percentage >= 75.0) printf("Distinction\n");
    else if (percentage >= 60.0) printf("First Division\n");
    else if (percentage >= 50.0) printf("Second Division\n");
    else if (percentage >= 40.0) printf("Third Division\n");
    else printf("Fail\n");
}

int main(void) {
    double marks[] = {72, 81, 64, 77, 69};
    size_t count = sizeof marks / sizeof marks[0];
    double percentage = calculate_percentage(marks, count);

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




plus2net.com



sadiya ramesh

13-07-2014

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.



✖
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