问题看起来像这样
https://i.imgur.com/u0LJO0g.png
我哪里出错了?
#include<stdio.h>
int main(){
int i,n;
int a[] = {3,5,7};
float x[] = {0,0,0};
printf("function f(x)=(x^3-2x^2+10x-5)/(x-10)\n");
for(i = 0;i<3;i++){
x[i] = (a[i]^3-2*(a[i]^2)+10*a[i]-5)/(a[i]-10);
}
for(n = 0;n<3;n++){
printf("if x is %d,f(x) is %f\n",a[n],x[n]);
}
}
我希望输出看起来像这样
if x is 3,f(x) is -5.14
if x is 5,f(x) is -24.00
if x is 7,f(x) is -103.33
但实际输出是
if x is 3,f(x) is -3.000000
if x is 5,f(x) is -7.000000
if x is 7,f(x) is -20.000000
^
在 C 中是 XOR,而不是求幂。int
s进行数学运算,您将得到int
结果。您需要将其中一些转换a[i]
为float
或double
获得浮点运算。本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句