| 网站首页 | 业界新闻 | 小组 | 交易 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛

已结贴   问题点数：18  回复次数：8

#include<stdio.h>
#define N 0.01
#define A 4

double F(double x,double a[]);
int main(){

double a0,a1,a2,a3;
double b0,b1;
double roof;
double x;
double mediate;

scanf("%fl %fl %fl %fl",&a0,&a1,&a2,&a3);
double a[A]{a0,a1,a2,a3};
scanf("%lf %lf",&b0,&b1);
mediate = b0+b1;

if(b0-b1<=N){
printf("%f",(b1-b0)/2);
}else{
do{
if(F(b0,a[])*F(mediate,a[])>0){
b0 = mediate;
} else{
b1 = mediate;
}
mediate = b0+b1;
roof = F(mediate,a[]);

}while(roof-(int)roof>=N);

printf("%f",roof) ;
}
return 0;

}

double F(double x,double a[]){
double F;
F = a[0]*x*x*x+a[1]*x*x+[a2]*x+a[3];
return F;
}

得分:0

[此贴子已经被作者于2020-1-12 11:35编辑过]

得分:0

得分:0

得分:0

得分:10

```#include<stdio.h>
#define N 0.01
#define A 4

double F(double x,double a[]);
int main() {

double a0,a1,a2,a3;
double b0,b1;
double roof;
double x;
double mediate;

scanf("%lf %lf %lf %lf",&a0,&a1,&a2,&a3);//第一处
double a[A] = {a0,a1,a2,a3};//第二处
scanf("%lf %lf",&b0,&b1);
mediate = b0+b1;

if(b0-b1<=N) {
printf("%lf",(b1-b0)/2);//第三处
} else {
do {
if(F(b0,a)*F(mediate,a)>0) {//第四处
b0 = mediate;
} else {
b1 = mediate;
}
mediate = b0+b1;
roof = F(mediate,a);//第五处

} while(roof-(int)roof>=N);

printf("%lf",roof) ;//第六处
}
return 0;

}

double F(double x,double a[]) {
double Fun;//第七处，我想这里应该不是递归吧？
Fun = a[0]*x*x*x+a[1]*x*x+a[2]*x+a[3];//第八处
return Fun;
}```
得分:0

3 -1 -3 1
-0.5 0.5

0.33
得分:0

#include <stdio.h>
#define N 0.000001
#define A 4
#include <math.h>

double F(double x,double a[]);
int main(){

double a0,a1,a2,a3;
double b0,b1;
double root;
double x;
double mediate;

scanf("%lf %lf %lf %lf",&a0,&a1,&a2,&a3);
double a[A] = {a0,a1,a2,a3};
scanf("%lf %lf",&b0,&b1);
mediate = (b0+b1)/2;

if(b1-b0<=N){
printf("%f",(b1-b0)/2);
}else{
do{
if(F(b0,a)*F(mediate,a)>0){
b0 = mediate;
} else{
b1 = mediate;
}
mediate = (b0+b1)/2;
root = mediate;

}while (fabs(F(b1,a)-F(b0,a)>=N));

printf("%.2f",root) ;
}
return 0;

}

double F(double x,double a[]){
double f;
f = a[0]*x*x*x+a[1]*x*x+a[2]*x+a[3];
return f;
}
得分:8

```#include<stdio.h>
#define E 0.01
#define A 4

double fun(double x, double a[]);
int main()
{
double b0, b1,tb0,tb1;
double a[A];
double fun(double x, double a[]);
double getValue(double a[], double b0, double b1);//递归函数

scanf("%lf%lf%lf%lf", &a[0], &a[1], &a[2], &a[3]);

scanf("%lf%lf", &b0, &b1);
tb0 = fun(b0, a);
tb1 = fun(b1, a);
if(tb0*tb1>0)printf("No\n");
else if (tb0==0)printf("value is :  %lf\n", b0);
else if (tb1 == 0)printf("value is :  %lf\n", b1);
else printf("value is :  %lf\n", getValue(a,b0,b1));

return 0;
}

double fun(double x, double a[])
{

return a[0] * x*x*x + a[1] * x*x + a[2] * x + a[3];
}

double getValue(double a[], double b0, double b1)
{
double temp,tb;
double fun(double x, double a[]);
tb = (b0 + b1) / 2;
temp = fun(tb, a);
if (((b0-b1<0?b1-b0:b0-b1) < E) || (temp == 0))return tb;//递归结束

else
{

if (temp*fun(b0, a) > 0)b0 = tb;//中点与b0符号相同，替换b0
else b1 = tb;//中点与b0符号不同，替换b1

return getValue(a, b0, b1);//递归调用
}
}
```
• 9
• 1/1页
• 1

Powered by Discuz, Processed in 0.050934 second(s), 8 queries.
Copyright©2004-2020, BCCN.NET, All Rights Reserved