此代码显示以下错误:
- 缺少)之前的类型
醇>
- calc:调用
的参数太少- 语法错误)Visual stuio 2013平台
mycode的:
#include "math.h"
void main()
{
float num[5];
float (calc (float num[5]));
calc(float num);/* transferring control to calc function)*/
getch();
}
float calc(float nun[5])
{
int i;
float num[5];
float sum, avg, sqmn1, sumsqmn = 0, sqsd = 0; float sd;
printf("\nEnter 5 numbers");
for (i = 0; i < 5; i = i + 1)
{
scanf("%f", &num[i]);
}
sum = 0;
for (i = 0; i < 5; i = i + 1)
{
sum = sum + num[i];
}
avg = sum / 5;
for (i = 0; i < 5; i = i + 1)
{
sqmn1 = (avg - num[i])*(avg - num[i]);
sumsqmn = sumsqmn + sqmn1;
}
sqsd = sumsqmn / 5;
sd = sqrt(sqsd);
printf("\nThe sum is %f", sum);
printf("\nThe average is %f", avg);
printf("\nThe stabdard deviation is %f", sd);
getch();
}
答案 0 :(得分:3)
float (calc (float num[5]));
在你的main()
中,究竟是什么?
IMO,它可以是,
float ff;
ff = calc(num);
除此之外,
#include <stdio.h>
缺失。float calc(float nun[5])
的正向声明。您可以将main()
重写为
int main()
{
float num[5];
float ff;
ff = calc(num);/* transferring control to calc function)*/
getch();
return 0;
}
但是,您也将num
从main()
传递到calc()
,但我发现您从未使用过它。你是做什么的?