# How to Calculate Harmonic Mean (HM) for Raw Data in C programming?

By | October 19, 2021

Calculate Harmonic Mean (HM) for Raw Data in C programming

```// Here, ll = lowerLimit
// cl = classLength
// nc = number of classes
// sf = sum of frequency
// f = frequency
#include<stdio.h>
#include<conio.h>
void main()
{
int ll,cl,up,nc,l[100],u[100],i,n,x[100],f[100],sf=0;
float fix[100],sfix=0.0;
clrscr();
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]);
fix[i]=(float)f[i]/(float)x[i];
sfix+=fix[i];
sf+=f[i];
}
printf(" Class Xi Fi Fi/Xi ");
for(i=0;i<nc;i++)
printf("%d-%d %d %d %.4f ",l[i],u[i],x[i],f[i],fix[i]);
printf(" Total %.4f",sfix);
printf(" sum of Fi/Xi is: %.4f",sfix);
printf(" %.4f",(float)sf/(float)sfix);

getch();
}```

Output: