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();
}
Output

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:

CCC Online Test 2021 CCC Practice Test Hindi Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Sarkari Exam Quiz