当前位置:网站首页>7-2 the cubic root of a number

7-2 the cubic root of a number

2022-06-26 13:23:00 White -

7-2 The third root of a number

Knowledge point : Two points

Given a floating-point number n, Find its third root .

Input format :
All in one line , Contains a floating-point number n(−10000≤n≤10000).

Output format :
All in one line , Contains a floating-point number , Represents the solution of the problem .

Be careful , The result is reserved 6 Decimal place .

sample input :

1000.00

sample output :

10.000000

Code :

#include<stdio.h>
#include<math.h>
double n;
int main()
{
    
    ///n(−10000≤n≤10000)
    double l=-10000;
    double r=10000;
    scanf("%lf",&n);
    while(r-l>=1e-8)
    {
    
        double mid=(l+r)/2;
        if(pow(mid,3)>n)
            r=mid;
        else
            l=mid;
    }
    printf("%.6lf",l);
}

202206260912 Japan

原网站

版权声明
本文为[White -]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/177/202206261124055857.html