#include<iostream>
using namespace std;
int main()
{
double a, p, q, r, s;
cout << "入力した整数の平方根を求めるプログラム" << endl;
cout << "正の整数を入力してください :";
cin >> a;
if (a < 0.0) {
cout << "正の整数を入力してください" << endl;
} else if (a == 0.0) {
cout << 0;
} else {
p = 0.0;
q = a + 1.0;
while (1) {
r = (p + q) / 2.0;
if (r == p || r == q)
break;
s = r * r;
if (s == a)
break;
else if (s < a)
p = r;
else
q = r;
}
cout << "√" << a << " = " << r << endl;
}
return 0;
}
I2luY2x1ZGU8aW9zdHJlYW0+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CmludCBtYWluKCkKewogICAgZG91YmxlIGEsIHAsIHEsIHIsIHM7CiAgICBjb3V0IDw8ICLlhaXlipvjgZfjgZ/mlbTmlbDjga7lubPmlrnmoLnjgpLmsYLjgoHjgovjg5fjg63jgrDjg6njg6AiIDw8IGVuZGw7CiAgICBjb3V0IDw8ICLmraPjga7mlbTmlbDjgpLlhaXlipvjgZfjgabjgY/jgaDjgZXjgYQgOiI7CiAgICBjaW4gPj4gYTsKICAgIGlmIChhIDwgMC4wKSB7CiAgICAgICAgY291dCA8PCAi5q2j44Gu5pW05pWw44KS5YWl5Yqb44GX44Gm44GP44Gg44GV44GEIiA8PCBlbmRsOwogICAgfSBlbHNlIGlmIChhID09IDAuMCkgewogICAgICAgIGNvdXQgPDwgMDsKICAgIH0gZWxzZSB7CiAgICAgICAgcCA9IDAuMDsKICAgICAgICBxID0gYSArIDEuMDsKICAgICAgICB3aGlsZSAoMSkgewogICAgICAgICAgICByID0gKHAgKyBxKSAvIDIuMDsKICAgICAgICAgICAgaWYgKHIgPT0gcCB8fCByID09IHEpCiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgcyA9IHIgKiByOwogICAgICAgICAgICBpZiAocyA9PSBhKQogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIGVsc2UgaWYgKHMgPCBhKQogICAgICAgICAgICAgICAgcCA9IHI7CiAgICAgICAgICAgIGVsc2UKICAgICAgICAgICAgICAgIHEgPSByOwogICAgICAgIH0KICAgICAgICBjb3V0IDw8ICLiiJoiIDw8IGEgPDwgIiA9ICIgPDwgciA8PCBlbmRsOwogICAgfQogICAgcmV0dXJuIDA7Cn0K