[Tutorial 7] 9.Calculate average marks of 4 subjects which, entered separately.

#include <stdio.h>

int main() {
float subject1, subject2, subject3, subject4, average;

    /* Input marks of each subject from the user*/
    printf("Enter marks of subject 1: ");
    scanf("%f", &subject1);
    printf("Enter marks of subject 2: ");
    scanf("%f", &subject2);
    printf("Enter marks of subject 3: ");
    scanf("%f", &subject3);
    printf("Enter marks of subject 4: ");
    scanf("%f", &subject4);

/* Calculate average marks*/
    average = (subject1 + subject2 + subject3 + subject4) / 4;

/* Display the average marks*/
    printf("The average marks of the four subjects is: %.2f\n", average);

return 0;
}


This program prompts the user to enter the marks of each of the four subjects separately, calculates the average, and then displays the result. Compile and run this program in a C compiler like Quincy or any other compiler of your choice.

Comments

Popular posts from this blog

Introduction To C

First C Program

Compilation process in c