# How to find Arithmetic mean of Continuous series in C programming?

By | October 19, 2021

Arithmetic mean of Continuous series in C programming

// Here, ll = lowerLimit
// cl = classLimit
// nc = class length
// sf = sum of frequency
// f = frequency
// am = assumed  mean
#include<stdio.h>
#include<conio.h>
int i,j,ll,up,cl,nc,l[100],u[100],f[100],sf,am;
float x[100],fx[100],sfx,fd[100],d[100],sfd,sfv,v[100],fv[100];
void getdata()
{
printf("Enter the lower limit: ");
scanf("%d",&ll);
printf("Enter the class length: ");
scanf("%d",&cl);
printf("Enter the total number of class: ");
scanf("%d",&nc);

for(i=0;i<nc;i++)
{
up=ll+cl;
l[i]=ll;
u[i]=up;
ll=up;
x[i]=((float)l[i]+(float)u[i])/2;
}
for(i=0;i<nc;i++)
{
printf("Enter the frequency for class %d-%d: ",l[i],u[i]);
scanf("%d",&f[i]);
}
}
void direct()
{
sf=0;
sfx=0;
for(i=0;i<nc;i++)
{
sf+=f[i];
fx[i]=x[i]*f[i];
sfx+=fx[i];
}
printf(" ");
for(i=0;i<30;i++)
printf("-");
printf(" Class Xi Fi FiXi ");
for(i=0;i<nc;i++)
printf("%d-%d %.2f %d %.2f ",l[i],u[i],x[i],f[i],fx[i]);
for(i=0;i<30;i++)
printf("-");
printf(" Total %d %.2f",sf,sfx);
printf(" The sum of Fi is: %d",sf);
printf(" The sum of FiXi is: %.2f",sfx);
printf(" The mean is : %.4f",sfx/sf);
}
void shortcut()
{
sf=0;
sfd=0;
printf("Enter the assumed mean: ");
scanf("%d",&am);
for(i=0;i<nc;i++)
{
d[i]=x[i]-am;
fd[i]=f[i]*d[i];
sf+=f[i];
sfd+=fd[i];
}
for(i=0;i<40;i++)
printf("-");
printf(" Class Xi Di Fi FiDi ");
for(i=0;i<nc;i++)
printf("%d-%d %.2f %.2f %d %.2f ",l[i],u[i],x[i],d[i],f[i],fd[i]);
for(i=0;i<40;i++)
printf("-");
printf(" Total %d %.2f",sf,sfd);
printf(" The assumed mean is: %d",am);
printf(" The sum of FiDi is: %.2f",sfd);
printf(" The sum of Fi is: %d",sf);
printf(" The mean is : %.4f",am+(sfd/sf));
}
void step()
{
sf=0;
sfv=0;
printf("Enter the assumed mean: ");
scanf("%d",&am);
for(i=0;i<nc;i++)
{
v[i]=(x[i]-am)/cl;
fv[i]=f[i]*v[i];
sf+=f[i];
sfv+=fv[i];
}
for(i=0;i<40;i++)
printf("-");
printf(" Class Xi Ui Fi FiUi ");
for(i=0;i<nc;i++)
printf("%d-%d %.2f %.2f %d %.2f ",l[i],u[i],x[i],v[i],f[i],fv[i]);
for(i=0;i<40;i++)
printf("-");
printf(" Total %d %.2f",sf,sfv);
printf(" The assumed mean is: %d",am);
printf(" The sum of FiUi is: %.2f",sfv);
printf(" The sum of Fi is: %d",sf);
printf(" The class lenght is: %d",cl);
printf(" The mean is : %.4f",am+((sfv/sf)*cl));
}
void main()
{
int choice;
while(1)
{
clrscr();
printf("The Mean for Continous Distribution ");
printf("1.Direct Method 2.Shortcut Method 3.Step Deviation Method 0.Exit ");
scanf("%d",&choice);

switch(choice)
{
case 1:
getdata();
direct();
break;

case 2:
getdata();
shortcut();
break;

case 3:
getdata();
step();
break;

case 0:
exit(0);
getch();
break;

default:
printf("Enter valid choice!");
break;
}
getch();
}
}

Output: