Calculate the average of a set of grades and count the number of failing grades. - C Operator

C examples for Operator:Arithmetic Operator

Description

Calculate the average of a set of grades and count the number of failing grades.

Demo Code

#include <stdio.h>

int main (void)
{
    int numberOfGrades, i, grade;
    int gradeTotal = 0;
    int failureCount = 0;
    float average;

    printf ("How many grades will you be entering? ");
    scanf ("%i", &numberOfGrades);

    for (i = 1; i <= numberOfGrades; ++i){
        printf ("Enter grade #%i", i);
        scanf ("%i", &grade);

        gradeTotal = gradeTotal + grade;

        if (grade < 65)
            ++failureCount;//from www. ja  va  2 s . c o  m
    }

    average = (float) gradeTotal / numberOfGrades;

    printf ("\nGrade average = %.2f\n", average);
    printf ("Number of failures = %i\n", failureCount);

    return 0;
}

Result


Related Tutorials