设计函数int sqrt(int x)
,计算 xxx 的平方根。
输入格式
输入一个 整数 xxx,输出它的平方根。直到碰到文件结束符(EOF
)为止。
输出格式
对于每组输入,输出一行一个整数,表示输入整数的平方根。
样例输入
1 2 3 4 5 6 7 8 9
样例输出
1 1 1 2 2 2 2 2 3
#include <iostream>
using namespace std;
int sqrt(int x){
if(x==1){
return 1;
}
for(int i=1;i<=x/2;i++){
if(i*i>x){
return i-1;
}
}
}
int main(){
int n;
while(cin >> n){
cout << sqrt(n) << endl;
}
return 0;
}