Programming Example
Program to calculate sum of 5 subjects and find percentage.
In this program, user will give marks for subject and it will return the sum or total and average of marks
#include<stdio.h>
#include<conio.h>
void main()
{
int s1,s2,s3,s4,s5,sum,total=500;
float per;
printf("enter marks of 5 subjects: \n");
scanf("%d%d%d%d%d",&s1,&s2,&s3,&s4,&s5);
sum=s1+s2+s3+s4+s5;
printf("sum=%d\n",sum);
per=(sum*100)/total;
printf("percentage=%f\n",per);
}
enter marks of 5 subjects:
66
65
88
74
95
sum=388
percentage=77.000000
Press any key to continue . . .
First read the algorithm, then study the program code line by line. After that, compare the code with the output and finally go through the explanation. This approach helps learners understand both the logic and the implementation properly.
After understanding this example, try to rewrite the same program without looking at the code. Then change some values or logic and run it again. This helps improve confidence and keeps learners engaged on the page for longer.