C语言高手帮下忙,谢!

2025-01-07 07:42:22
推荐回答(4个)
回答1:

#include
#include

float a[16];
int n,k;
float p(float x),x;
float epsilon;
float xres,xlow,xup,R,E;//定义为全局变量即可
void main (void)
{

do{
printf("Enter the polynomial's degree:");
scanf("%d",&n);
if(n>15)
printf("degree too high!\n");
else if(n<3)
printf("degree too low!\n");
}
while(n>=3&&n<=15);
for(k=0;k<=n;k++){
printf("Enter coefficient of degree %d:",k);
scanf("%f",&a[k]);
}

printf("enter the epsilon:");
scanf("%f",&epsilon);
R=1,xlow=-10,xup=10;
while (R>0);
{xlow=2*xlow;
xup=2*xup;
R=p(xlow)*p(xup);
}
for(E=100;E>epsilon;)
{
xres=0.5*(xlow+xup);
if(p(xlow)*p(xres)<0)
xup=xres;
else
xlow=xres;
E=xup-xlow;
}
printf("the result is:%f",xres);
}
float p(float x)//函数定义应该在主函数外
{
float p1=a[0];
float px=1;
for(k=1;k<=n;k++)
{px=px*x;
p1=p1+a[k]*px;
}
return (p1);
}

回答2:

检查一下,返回值与接收变量的类型是否一致.朋友.

回答3:

返回值与接收变量不一样出现的是warning,不是error,而且warning的显示是conversion,possible loss of data(转换可能丢失数据),不是Extraneous
return value,所以还是楼主把代码贴出来看看

回答4:

将代码贴出来看看