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. This program is beneficial for beginners as it helps them understand basic arithmetic operations and formatting output in C.

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

Important Points to Remember

  • Data Type Compatibility : Use appropriate data types (e.g., int for whole numbers, float for decimal numbers) for variables to avoid data loss.

  • Precision in Calculations : Be mindful of precision issues that may arise during calculations involving division and percentage calculations.

  • Format Output Properly : Use formatting specifiers like %d and %f to display total, average, and percentage marks neatly

  • Handle Input Carefully : Ensure that input is taken correctly, and validate user inputs to avoid errors.

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

Importance of Practicing this Program for Beginners

As beginners in the world of programming, it is crucial to understand the significance of practicing programs like the one we are discussing today. The C program to find total, average, and percentage marks of subjects is not just a mere exercise; it is a stepping stone in your journey to becoming a proficient programmer. Here's why practicing this program is so important:
  • Problem-solving Skills Development : This program challenges you to think critically and logically to solve a real-world problem. By breaking down the task into smaller, manageable parts, you will develop valuable problem-solving skills that are essential in any programming endeavor.

  • Understanding Basic Arithmetic Operations : Programming is all about manipulating data and performing operations on it. This program helps you understand and master basic arithmetic operations like addition, division, and multiplication, which form the foundation of more complex programming concepts.

  • Application of Programming Concepts : The concepts you learn while writing this program, such as variables, data types, loops, and conditional statements, are fundamental to programming. Mastering these concepts early on will make it easier for you to grasp more advanced topics in the future.

  • Preparation for Real-world Scenarios : In the real world, programmers often need to calculate totals, averages, and percentages in various contexts. By practicing this program, you are preparing yourself to tackle similar tasks in your future programming projects or academic pursuits.

  • Building Confidence : Successfully writing and executing this program will boost your confidence and motivate you to take on more challenging programming tasks. It is a tangible demonstration of your progress and competence as a programmer.

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