C Program to Find Total, Average and Percentage Marks of Subjects

In this C program, we will learn about how to find average and percentage marks of all subjects. We will first read the number of subjects and then marks of all subjects using for loop and scanf function. To get the total marks, we add the marks of all subject and to calculate average marks and percentage we will use below mentioned formulae.

Required Knowledge

  • Average Marks = Marks_Obtained/Number_Of_Subjects
  • Percentage of Marks = (Marks_Obtained/Total_Marks) X 100

C program to find total, average and percentage marks of subjects

#include <stdio.h>  
  
int main(){
    int subjects, i;  
    float marks, total=0.0f, averageMarks, percentage;
  
    printf("Enter number of subjects\n");  
    scanf("%d", &subjects);  
  
    printf("Enter marks of subjects\n");  
    for(i = 0; i < subjects; i++){
     scanf("%f", &marks);
     total += marks; 
    }  
    averageMarks = total / subjects;
    /* Each subject is of 100 Marks*/  
    percentage = (total/(subjects * 100)) * 100;  
  
    printf("Total Marks = %0.4f\n",subjects,total);  
    printf("Average Marks = %.4f\n", averageMarks);  
    printf("Percentage = %.4f", percentage);  
  
    return 0;  
} 

Output
Enter number of subjects
4
Enter marks of subjects
50
60
70
80
Total Marks = 260.0000
Average Marks = 65.0000
Percentage = 65.0000
Related Topics
C program to add n numbers
C program for addition, subtraction, multiplication, division and modulus of two numbers
C program to add digits of a number
C program to swap two numbers
C program to generate armstrong numbers
C program to check a number is palindrome or not
C program to find hcf and lcm of two numbers
C program to check whether a number is magic number
C program to convert string to integer
List of all C programs