给定一个数字及其根值,找到一个数字的第 n 个根

given a number and its root value, finding nth root of a number

本文关键字:一个 数字 个根      更新时间:2023-10-16

有人可以解释下面提到的代码吗?

double b=0.0;
double a=0.001;
double r=0;
printf("Type the number and root value n");
scanf("%lf %lf",&b,&r);
while(pow(a,r)<(b + 0.05)){
a += 0.001;
}
printf("The %f root of %f is = %fn",r,b,a);
return 0;

例如,如果数字为 32,根值为 5

输出:32 的 5 根是 = 2

这是一种简单的试错法,您将随机的小数作为基础,并将其递增到幂(在您的例子中为 r(,直到它大于或等于您想要的数字。

在这里,你的随机数是a,你每次递增,直到pow大于b。