Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- const double eps = 1e-6;
- int main(){
- double x = 0;
- scanf("%lf", &x);
- double tmp = (x >= 0 ? x : -x);
- double left = 0, right = tmp;
- double mid = 0;
- while (right - left > eps){
- mid = (left + right) / 2;
- if (mid * mid * mid > tmp)
- right = mid;
- else
- left = mid;
- }
- double cubeRoot = (x >= 0 ? (left + right) / 2 : - (left + right) / 2);
- printf("%lf\n", cubeRoot);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement