//assumed mean method
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
/* mvx--Middle value of observation(x)
xup--Upper point of observation
xlow--Lower point of observation
f--frequency of observation
Tf--Total of frequency
n--number of observation
a--Assumed mean
c--class length
d--difference of observation and assumed mean
fd--multiplication of frequency and difference
Tfd--total of fd
mean--finally mean */
int mvx[100],xup[100],xlow[100],f[100],Tf=0,n,i,a,c,d[100],fd[100];
float mean,Tfd=0;
printf("\t\tProgram to find mean with assumed mean method:\n\n");
printf("Enter the number of observation:");
scanf("%d",&n);
printf("Enter the data:\n");
printf("X-->");
for(i=1;i<=n;i++)
{
printf("\t");
//taking data from user:
scanf("%d",&xlow[i]);
scanf("%d",&xup[i]);
}
printf("Printing the observation:\n");
for(i=1;i<=n;i++)
{
//just printing data
printf("%d-%d\t",xlow[i],xup[i]);
}
printf("\nMV(x)-->");
for(i=1;i<=n;i++)
{
//finding middle value of x amd prntfing it
mvx[i]=xup[i]+xlow[i]/2;
printf("\t%d",mvx[i]);
}
printf("\nEnter the frequency:\n");
printf("F-->");
for(i=1;i<=n;i++)
{
//taking frequency from user and making total of it
printf("\t");
scanf("%d",&f[i]);
Tf=Tf+f[i];
}
//finding class length
c=xup[1]-xlow[1];
//assuming mean from the user
printf("Assume any observation from data:");
scanf("%d",&a);
printf("D-->");
for(i=1;i<=n;i++)
{
//calculating d and printing
printf("\t");
d[i]=(mvx[i]-a)/c;
printf("%d",d[i]);
}
printf("\nFD-->");
for(i=1;i<=n;i++)
{
//calculating fd and printing
fd[i]=f[i]*d[i];
printf("\t%d",fd[i]);
Tfd=Tfd+fd[i];
}
//calculating mean
mean=a+(Tfd/Tf)*c;
printf("\nMean of the data is:%f",mean);
getch();
}
这是一个通过假设均值法找到具有类长度的连续数据的均值的程序。 我在程序的注释部分添加了变量的所有其他信息。 这里有2个相同的错误#34;这里不允许声明&#34;我已经声明了所有变量。 我已经做了很多努力摆脱它,但我不能帮助我摆脱它...
答案 0 :(得分:0)
如果您使用较旧的编译器,我认为所有C99之前的编译器,函数中的所有声明都必须在任何函数调用之前。移动线
clrscr();
声明所有变量后,即在行
之后移动它float mean,Tfd=0;
如果编译器支持C99(可能使用编译器标志),则可以使用现有代码。然后你需要找到如何启用它。