//二分法 #include <stdio.h> int main() { float a; scanf("%f", &a); float left = -3, right = 3; while (left <= right) { float mid = (left + right) / 2; if (mid * mid * mid < a) left = mid + 0.01; else right = mid - 0.01; } printf("%.1f", left); return 0; } //牛顿迭代法 import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); float a = sc.nextFloat(); float ans = a; while (Math.abs(ans * ans * ans - a) > 0.01) { ans -= (ans * ans * ans - a) / (ans * ans * 3); } System.out.printf("%.1f", ans); } } #Python版代码 number = float(input()) if number >= 0:print(f"{number ** (1 / 3):.1f}") else:print(f"{-(-number) ** (1 / 3):.1f}")