Programming Examples

Calculate the sum and average of five subjects


Calculate the sum and average of five subjects

Solution

#include<stdio.h>
void main()
{
int a,b,c,d,e,sum=0,i;
float avg;
clrscr();
printf(“\nEnter The Marks of Five Subjects”);
for(i=1;i<=5;i++)
{
 printf(“\n[%d] Student:”,i);
 if(scanf(“%d %d %d %d %d”,&a,&b,&c,&d,&e)==5)
 {
 sum=a+b+c+d+e;
 avg=sum/5;
 printf(“\n Total Marks of Student[%d] %d”,i,sum);
 printf(“\n Average Marks of Student[%d] %f\n”,i,avg);
 }
 else
 {
 clrscr();
 printf(“\n Type Mismatch”);
 }
}
getch();
}
▶ RUN

Output/ Explanation:

OUTPUT:

Enter The Marks of Five Subjects

[1] Student: 58 52 52 56 78

Total Marks of Student[1] 296

Average Marks of Student[1] 59.000000

[2] Student:

Latest Current Affairs 2025 Online Exam Quiz for One day Exam Online Typing Test CCC Online Test Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Online MBA 2 years Online MCA Online BCA Best Website and Software Company in Allahabad