求纯手工计算方法,我计算不下去了。
#include <stdio.h> void main() { int a, n;//计算a的开n次方 double low, high, middle, x; scanf("%d%d", &a, &n); int i, j, tmp; for (i=1; i<a; i++) { tmp = 1; for (j=0; j<n; j++) { tmp *= i; } if (tmp >= a) { break; } } low = i - 1; high = i; while (1) { middle = (low+high)/2; x = 1; for (j=0; j<n; j++) { x *= middle; } if (x - a < 0.0001 && x - a > -0.0001) { printf("%lf\n", middle); break; } if (x > a) { high = middle; } else { low = middle; } } }