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

Write a program in C to read marks of N subjects and find Total, Average and Percentage marks.
Wap in C to find average and percentage marks of all subjects.

Required Knowledge

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.

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

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

 * C program to calculate total, average and percentage of all subjects 
#include <stdio.h>  
int main(){
    int subjects, i;  
    float marks, total=0.0f, averageMarks, percentage;
     * Take number of subjects as imput from user 
    printf("Enter number of subjects\n");  
    scanf("%d", &subjects);  
     * Take marks of subjects as input 
    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 of %d Subjects = %0.4f\n",subjects,total);  
    printf("Average Marks = %.4f\n", averageMarks);  
    printf("Percentage = %.4f", percentage);  
    return 0;  

Enter number of subjects
Enter marks of subjects
Total Marks of 4 Subjects = 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