Code Learning#CPP#7595
Back
Percentage Calculation
Source Code
Run Output
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.
