中易网

唉。。。菜鸟C语言求改错

答案:1  悬赏:0  
解决时间 2021-01-10 20:54
  • 提问者网友:遮云壑
  • 2021-01-10 14:33
唉。。。菜鸟C语言求改错
最佳答案
  • 二级知识专家网友:行路难
  • 2021-01-10 15:19
#include 
#include 
#include 

double rectanglemethod(float a,float b,float x1,double f[],int n);
double trapezoidalmethod(float a,float b,float x1,double f[],int n);
double parabolicmethod(float a,float b,float x1,double f[],int n);

int main()
{
double f[100],y,a,b,x1,x;
double I;
int i,n;
printf("请输入n(n<101)");
scanf("%d",&n);
printf("请输入a、b");
scanf("%lf %lf",&a,&b);
x1=(a-b)/n;
for(i=0;i {
x=a+x1*i;
y=cos(1/(1+x*x));
f[i]=y;
}
I = rectanglemethod(a,b,x1,f,n);
printf("%f ",I);
I = trapezoidalmethod(a,b,x1,f,n);
printf("%f ",I);
I = parabolicmethod(a,b,x1,f,n);
printf("%f
",I);
return 0;
}

double rectanglemethod(float a,float b,float x1,double f[],int n)
{
int i;
double I1=0;
for(i=0;i I1=I1+f[i]*x1;
return I1;
}

double trapezoidalmethod(float a,float b,float x1,double f[],int n)
{
int i;
double I2=0;
for(i=1;i I2=I2+f[i]*x1;
I2=(f[0]+f[n])*0.5*x1+I2;
return I2;
}

double parabolicmethod(float a,float b,float x1,double f[],int n)
{
int i,r,t,s;
s=n/2+1;
double I3=0;
for(i=1;i {
r=2*i-1;
I3=I3+4/3.0*f[r]*x1;
}
for(i=1;i {
t=2*i;
I3=I3+2/3.0*f[t]*x1;
}
I3=I3+1/3.0*(f[0]+f[n])*x1;
return I3;
}你代码太秀了,帮你把错误改掉了,结果不对的话自己改吧,不会微积分

我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息!
大家都在看
推荐信息