C语言中主函数怎么向声明的函数传递多个参数?
如题,下面的代码报错说参数过多,该如何解决?#include<stdio.h>voidcal(floatn);intmain(void){floatnumber1,num...
如题,下面的代码报错说参数过多,该如何解决?
#include<stdio.h>
void cal(float n);
int main(void)
{
float number1,number2;
scanf("%f %f",&number1,&number2);
while((scanf("%f %f",&number1,&number2))==2)
{
cal(number1,number2); //报错说这一行声明参数过多,不知道该如何解决?
printf("over!");
scanf("%f %f",&number1,&number2);
printf("Please enter another two floats\n");
}
printf("IUPUT ERROR!\n");
return 0;
}
void cal(float n)
{ double number3,number4,results;
results=(number3-number4)/(number3*number4);
printf("%f",results);
} 展开
#include<stdio.h>
void cal(float n);
int main(void)
{
float number1,number2;
scanf("%f %f",&number1,&number2);
while((scanf("%f %f",&number1,&number2))==2)
{
cal(number1,number2); //报错说这一行声明参数过多,不知道该如何解决?
printf("over!");
scanf("%f %f",&number1,&number2);
printf("Please enter another two floats\n");
}
printf("IUPUT ERROR!\n");
return 0;
}
void cal(float n)
{ double number3,number4,results;
results=(number3-number4)/(number3*number4);
printf("%f",results);
} 展开
2个回答
展开全部
#include<stdio.h>
void cal(float a, float b); /*根据你的意思看,改成这样*/
int main(void)
{
float number1,number2;
scanf("%f %f",&number1,&number2);
while((scanf("%f %f",&number1,&number2))==2)
{
cal(number1,number2); //报错说这一行声明参数过多,不知道该如何解决?
printf("over!");
scanf("%f %f",&number1,&number2);
printf("Please enter another two floats\n");
}
printf("IUPUT ERROR!\n");
return 0;
}
void cal(float a, float b)/*根据你的意思看,改成这样*/
{ double results;
results=(a-b)/(a*b);
printf("%f",results);
}
追问
谢谢,也就是主函数向自定义函数传递多个参数需要在自定义函数原型中声明?
追答
yes。传递几个参数就声明几个参数。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询