You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
977 B

2 years ago
#include <bits/stdc++.h>
using namespace std;
/*
10000>=a>=-10000
*/
double sqrt(int n) {
double x = n;
for (int i = 1; i <= 100; i++) x = (x * x + n) / (2 * x);
return x;
}
double sqrt3(int n) {
double x = n;
for (int i = 1; i <= 100; i++) x = (2 * x * x * x + n) / (3 * x * x);
return x;
}
double sqrt4(int n) {
double x = n;
for (int i = 1; i <= 100; i++) x = (3 * x * x * x * x + n) / (4 * x * x * x);
return x;
}
double sqrt5(int n) {
double x = n;
for (int i = 1; i <= 100; i++) x = (4 * x * x * x * x * x + n) / (5 * x * x * x * x);
return x;
}
int main() {
// 求n的平方根和立方根
double n;
cin >> n;
// 平方根
printf("%.6lf\n", sqrt(n));
// 立方根
printf("%.6lf\n", sqrt3(n));
// 4次方根
printf("%.6lf\n", sqrt4(n));
// 5次方根
printf("%.6lf\n", sqrt5(n));
return 0;
}