Take marks of 5 subjects in integers, and find the total, average in float in C

 Take marks of 5 subjects in integers, and find the total, average in float  in C

Program:


#include <stdio.h>


int main() {

    int m1, m2, m3, m4, m5, total;

    float average;


    // Input marks

    printf("Enter marks for 5 subjects (out of 100):\n");

    scanf("%d %d %d %d %d", &m1, &m2, &m3, &m4, &m5);


    // Total and average calculation

    total = m1 + m2 + m3 + m4 + m5;

    average = total / 5.0; // Ensure float division


    // Output

    printf("Total Marks = %d\n", total);

    printf("Average Marks = %.2f\n", average);


    return 0;

}

Output:




Comments