【发布时间】:2021-12-15 02:47:16
【问题描述】:
嗨,我在 c 中找到多项式的总和,没有大量,我有这个错误说“二进制的无效操作数+(有'float()(int,int,int)'和'float ()(int, int, int)'"
这里是代码
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
float p6(int p6, int x, int a){ `function to find pow`
p6=pow(x, 6);
p6=a*p6;
return p6;
}
float p5(int p5, int x, int a){ `small function`
p5=pow(x, 5);
p5=p5*a;
return p5;
}
float p4(int p4, int x, int a){
p4=pow(x, 4);
p4=a*p4;
return p4;
}
float p3(int p3, int a, int x){
p3=pow(x, 3);
p3=a*p3;
return p3;
}
float p2(int p2, int a, int x){
p2=pow(x, 2);
p2=a*p2;
return p2;
}
main (){ `main function starts here`
int i, a;
double sum=0;
float x;
printf("x-iin utgiig oruul"); `value of x`
scanf("%lf", &x);
printf("a1-a6 toog oruul"); `value of coefficents`
for(i=1; i<=6; i++){ `for coeffincents`
scanf("%d", &a);
}
sum=p6+p5+p4+p3+p2+a*x; `error occurs here`
printf("%d", sum);
system("pause");
return 0;
}
【问题讨论】:
-
有很多错误。首先,'scanf("%d", &a);'使用相同的目标地址调用了六次,因此丢失了前五个输入的值。
-
然后,要调用带参数的函数,您必须提供参数。
-
你应该缩进你的代码并在函数之间添加空行,否则很难理解。
-
为什么 p2,p3 的参数顺序与其他函数不同?
-
为什么所有这些不同的功能呢?一个会做的。
标签: c compiler-errors binary pow polynomial-math