一个C的求根方程问题,急

来源:百度知道 编辑:UC知道 时间:2024/05/30 13:54:54
请问如何在STDIO.H下面写一个C程序求数字的根?
具体输入是
root(1, 3) = 1 (1 x 1 x 1 = 1). root(64, 3) = 4 (4 x 4 x 4)
这样

还有一个是英文题目:

Create a ln function that takes a float, and returns the number that is the power of 2.718 needed to get to that given float. So (ln(x) = y, where 2.718 raised to the power of y = x). The result should be within 0.01 of the perfect answer.

因为不知道是什麽意思,希望能有知道的人帮忙解答一下,可能的话最好能附上程序

急求,万分感谢

//求解开n次方根函数root()
double root(double c,int n)
{
int i;
double f=1e-6;
double X,init,output, X1;
double sub;
if(n>1)
{
X=c/2;X1=c;
do
{
sub=X-X1;
if(sub<0)
sub=-sub;
X1=X;init=1;
for(i=1;i<=n;++i)
init=X*init;//求X的n次方;
X=X-(init-c)/(n*init/X);//牛顿迭代公式;
}while(sub>f);
output=X;
}
else output=c;
return output;
}

如果允许用 数学库
#include <math.h>

root() 可用 pow 计算。pow(x,1.0/3.0) 就是开3次方
否则用 级数展开等法计算。

英文,就是叫你编一个 求自然对数 的函数 计算。精度到0.01. ( 用级数展开计算,或用1/x 的积分从1到t--ln(t)计算) .