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.
Created: 1-Mar-2026 16:02 | Updated: 2-Sep-2026 16:23|
