#include <stdio.h>
double mabs(double x){ return (x < 0)? -x : x; }
int main(void) {
double num = 8;
int rootDegree = 3;
printf("Число, корень которого считаем а = %f\n", num
); printf("Корень степени n = %d\n", rootDegree
);
double eps = 0.00001;
double root = num / rootDegree;
double rn = num;
int countiter = 0;
while(mabs(root - rn) >= eps){
rn = num;
for(int i = 1; i < rootDegree; i++){
rn = rn / root;
}
root = 0.5 * ( rn + root);
countiter++;
}
printf("Число итераций = %i\n", countiter
);
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+Cgpkb3VibGUgbWFicyhkb3VibGUgeCl7IHJldHVybiAoeCA8IDApPyAteCA6IHg7IH0gCgppbnQgbWFpbih2b2lkKSB7Cglkb3VibGUgbnVtID0gODsKCWludCByb290RGVncmVlID0gMzsKCglwcmludGYoItCn0LjRgdC70L4sINC60L7RgNC10L3RjCDQutC+0YLQvtGA0L7Qs9C+INGB0YfQuNGC0LDQtdC8INCwID0gJWZcbiIsIG51bSk7IAoJcHJpbnRmKCLQmtC+0YDQtdC90Ywg0YHRgtC10L/QtdC90LggbiA9ICVkXG4iLCByb290RGVncmVlKTsgCgkKCWRvdWJsZSBlcHMgPSAwLjAwMDAxOwoJZG91YmxlIHJvb3QgPSBudW0gLyByb290RGVncmVlOwoJZG91YmxlIHJuID0gbnVtOwoJaW50IGNvdW50aXRlciA9IDA7Cgl3aGlsZShtYWJzKHJvb3QgLSBybikgPj0gZXBzKXsKCSAgICBybiA9IG51bTsKCQlmb3IoaW50IGkgPSAxOyBpIDwgcm9vdERlZ3JlZTsgaSsrKXsKCQkJcm4gPSBybiAvIHJvb3Q7CgkJfQoJCXJvb3QgPSAwLjUgKiAoIHJuICsgcm9vdCk7CgkJY291bnRpdGVyKys7Cgl9CgkKCXByaW50Zigicm9vdCA9ICVmXG4iLCByb290KTsgCglwcmludGYoItCn0LjRgdC70L4g0LjRgtC10YDQsNGG0LjQuSA9ICVpXG4iLCBjb3VudGl0ZXIpOyAKCQoJcmV0dXJuIDA7Cn0=