To calculate average and percentage marks of a student in C++ programming, you have to ask to the user to enter marks obtained in some number of subjects (5 subjects here).
Place summation of 5 subject's marks in a variable say sum and place sum/5 in a variable say avg (average of 5 subjects) then place sum/500*100 in a variable say perc (percentage marks), then display the result on the screen as shown here in the following program.
Following C++ program ask to the user to enter the marks obtained in 5 subjects to calculate and display the average and percentage marks :
/* C++ Program - Calculate Average and Percentage Marks */ #include<iostream.h> #include<conio.h> void main() { clrscr(); int mark[5], i; float sum=0; cout<<"Enter marks obtained in Physics, Chemistry, Maths, CS, English :"; for(i=0; i<5; i++) { cin>>mark[i]; sum=sum+mark[i]; } float avg=sum/5; float perc; perc=(sum/500)*100; cout<<"Average Marks = "<<avg; cout<<"\nPercentage = "<<perc<<"%"; getch(); }
When the above C++ program is compile and executed, it will produce the following result:
You may like the same program in other programming languages: