How to find sum, average and percentage in array?

Below code will help you to code for finding sum, average percent and percent division.

#include<conio.h>
#include<stdio.h>
void main ()
{
int a[5],i,sum=0,n=5;
float average;
clrscr();
printf(“Enter number of student as Phy,Chem,Math,Hindi,English\n”);
for(i=0;i<=n-1;i++)
{
scanf(“%d”,&a[i]);
}
for(i=0;i<=n-1;i++)
{
sum=sum+a[i];
}
printf(“Your total number is :%d\n”,sum);
average=sum/(float)n;
printf(“Your total percent:=%0.2f%”,average);
if(average<=40)
{
printf(“Student is Fail”);
}
else
if(average>40&&average<=59)
{
printf(“Student has pass & got III division\n”);
}
else
if(average>=60&&average<=79)
{
printf(“Student has pass & got II division”);
}
else
if(average>79&&average<=100)
{
printf(“Student has got I division\n”);
}
getch();
}

After Running program 🙂

Leave a Reply