Object
Write a program to read the marks of 5 subjects of 3 students. Find the total and percentage of each student and print it.
Algorithm
- Declare integer variables a, b, c, d, e, t and i.
- Declare float variable p.
- Set i = 1.
- Repeat WHILE i <= 3
- Read marks of five subjects a, b, c, d and e.
- t = a + b + c + d + e.
- p = (t/500)*100
- Write total marks t and percentage p.
- i++.
- [End of WHILE loop.]
- Exit.
Flowchart

C++ Source Code
// program 50
#include<iostream>
#include <iomanip>
using namespace std;
int main()
{
int a, b, c, d, e, t, i;
float p;
i = 1;
while(i <= 3)
{
cout << "Enter marks in Physics: ";
cin >> a;
cout << "Enter marks in Mathematics: ";
cin >> b;
cout << "Enter marks in Computer Science: ";
cin >> c;
cout << "Enter marks in Urdu: ";
cin >> d;
cout << "Enter marks in English: ";
cin >> e;
t = a + b + c + d + e;
p = (t / 500.0) * 100.0;
cout << "\nThe total marks are: " << t;
cout << "\nThe percentage is: " << fixed << setprecision(2) << p << "%\n\n";
i++;
}
return 0;
}
C Source Code
/*program 50*/
#include<stdio.h>
int main()
{
int a, b, c, d, e, t, i;
float p;
i = 1;
while(i<=3)
{
printf("Enter marks in Physics: ");
scanf("%d", &a);
printf("Enter marks in Mathematics: ");
scanf("%d", &b);
printf("Enter marks in Computer Science: ");
scanf("%d", &c);
printf("Enter marks in Urdu: ");
scanf("%d", &d);
printf("Enter marks in English: ");
scanf("%d", &e);
t = a+b+c+d+e;
p = (t/500.0)*100.0;
printf("\nThe total marks are: %d", t);
printf("\nThe percentage is: %.2f%" "%%\n\n", p);
i++;
}
return 0;
}
Output
Enter marks in Physics: 37
Enter marks in Mathematics: 85
Enter marks in Computer Science: 74
Enter marks in Urdu: 51
Enter marks in English: 63
The total marks are: 310
The percentage is: 62.00%
Enter marks in Physics: 87
Enter marks in Mathematics: 44
Enter marks in Computer Science: 96
Enter marks in Urdu: 67
Enter marks in English: 46
The total marks are: 340
The percentage is: 68.00%
Enter marks in Physics: 68
Enter marks in Mathematics: 45
Enter marks in Computer Science: 86
Enter marks in Urdu: 35
Enter marks in English: 67
The total marks are: 301
The percentage is: 60.20%
