In this tutorial, you will learn to write a code on how to calculate the average percentage marks in C++. You may go through the following topics in C++:
We will do calculate the total marks, average, and then the percentage of the subjects entered by the user. The program also takes the user input for the marks obtained in the subjects.
How to find the average and Percentage of marks?
Total Marks = Sum of the marks of all subjects
Average Marks = Total Marks/No. of subjects
Percentage = ((marks obtained)/(total marks) *100)
C++ Program to find Total, Average and Percentage Marks
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | #include <iostream> using namespace std; int main() { int sub, i; float marks, total = 0.0 f, avg, perc; cout << "Enter the number of subjects: "; cin >> sub; cout << "Enter marks on each subject:\n"; for (i = 0; i < sub; i++) { cin >> marks; total += marks; } // Average Calculation avg = total / sub; // Each marks is out of 100 perc = (total / (sub *100)) *100; cout << "Total Marks Obtained: " << total; cout << "\nAverage Marks: " << avg; cout << "\nPercentage: " << perc; return 0; } |
Output:
Enter the number of subjects: 5
Enter marks on each subject:
84
67
62
80
76
Total Marks Obtained: 369
Average Marks: 73.8
Percentage: 73.8
Here, the total marks are taken as 100 on each subject, you may take the total marks from the users too.