Detailed Print – CSKC
Sign In

Search

siteicon
Code Learning#CPP#7595 Back

Percentage Calculation

Source Code

		 

Click to open popup

Run Output

Enter marks obtained in 3 subjects: 34 56 67
The percentage marks are: 52.3333 %

Code Understanding

This program calculates the percentage of marks obtained in three subjects.
• #include allows input and output commands.
• float sub1, sub2, sub3, marks, perc; declares variables for marks and percentage.
• cin >> sub1 >> sub2 >> sub3; takes marks of three subjects from the user.
• marks = sub1 + sub2 + sub3; adds all marks.
• perc = (marks / 300) * 100; calculates percentage (assuming each subject is out of 100).
• cout << … displays the percentage on the screen.
• return 0; ends the program.