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.0000Related Topics