求帮忙看一下,double arr[]括号内的值怎么才能改成非具体值,也就是不规定上限呢
const double eps = 1e-15;
double arr[70000000];
int n, k, i;
double m,p,u,y;
double j,sum,v;
double f(double x)
{
y = 0.0;
for (k=n; k>=0; k--)
{
y = y + arr[k] * pow(x,k);
}
return y;
}
int main()
{
printf("The function is like y = [(arr[n])x^n] + [(arr[n-1])x^(n-1)] + [(arr[n-2])x^(n-2)] + ... + [(arr[1])x] + arr[0]\n");
printf("Input n :");
scanf("%d",&n);
if (n<1)
{
printf("n is too little.\n");
return 1;
}
i = n;
for (i=n; i>=0; i--)
{
printf("Input the arr[%d]: ",i);
scanf("%lf", &arr[i]);
}
printf("\nEnter the range[m,p]:");
scanf("%lf%lf",&m,&p);
if (f(m)*f(p)<= 0.0)
{
while (fabs(m-p)>eps)
{
v=(m+p)/2.0;
sum=f(v);
if (fabs(sum)<eps)
{
break;
}
else
{
if(f(v)*f(m)<=0)
{
p=v;
}
else
{
m=v;
}
}
}
j=(m+p)/2.0;
printf("\nThe root x is%lf\n",j);
}
else
{
printf("f(m)*f(p)> 0.0, It can not solve by this method.");
}
return 0;
}
新人求帮助,谢谢了
double arr[70000000];
int n, k, i;
double m,p,u,y;
double j,sum,v;
double f(double x)
{
y = 0.0;
for (k=n; k>=0; k--)
{
y = y + arr[k] * pow(x,k);
}
return y;
}
int main()
{
printf("The function is like y = [(arr[n])x^n] + [(arr[n-1])x^(n-1)] + [(arr[n-2])x^(n-2)] + ... + [(arr[1])x] + arr[0]\n");
printf("Input n :");
scanf("%d",&n);
if (n<1)
{
printf("n is too little.\n");
return 1;
}
i = n;
for (i=n; i>=0; i--)
{
printf("Input the arr[%d]: ",i);
scanf("%lf", &arr[i]);
}
printf("\nEnter the range[m,p]:");
scanf("%lf%lf",&m,&p);
if (f(m)*f(p)<= 0.0)
{
while (fabs(m-p)>eps)
{
v=(m+p)/2.0;
sum=f(v);
if (fabs(sum)<eps)
{
break;
}
else
{
if(f(v)*f(m)<=0)
{
p=v;
}
else
{
m=v;
}
}
}
j=(m+p)/2.0;
printf("\nThe root x is%lf\n",j);
}
else
{
printf("f(m)*f(p)> 0.0, It can not solve by this method.");
}
return 0;
}
新人求帮助,谢谢了
...全文
相关推荐
java String 转成Double二维数组的方法
下面小编就为大家带来一篇java String 转成Double二维数组的方法。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
sizeof()里面的值
对c语言中sizeof进行总结!!sizeof的概念 sizeof的使用方法 、sizeof的结果 sizeof与其他操作符的关系
程序的逻辑(2) - 赋值
Java中基本类型、数组、对象的赋值有明显不同,本文介绍byte int short long boolean float char double等基本类型和数组的赋值。
详细解析C语言中的sizeof
详细解析C语言中的sizeof详细解析
C语言出错中英文对照
C语言编程时需要的错误指导。非常实用。 例如: Ambiguous operators need parentheses 不明确的运算需要用括号括起 Ambiguous symbol ``xxx`` 不明确的符号 Argument list syntax error 参数表法 Array bounds missing 丢失数界限符


非技术区
