#2528. 2024 CSP-J1 真题 · 完善程序(判断平方数)
2024 CSP-J1 真题 · 完善程序(判断平方数)
2024 CSP-J1 真题(120 分钟,总分 100 分)
完善程序(判断平方数)(共 5 题,共 15.0 分)
1. (判断平方数)问题:给定一个正整数 n,希望判断这个数是否为完全平方数,即存在一个正整数 x 使得 x 的平方为 n。
试补全程序。
#include<iostream>
#include<vector>
using namespace std;
bool isSquare(int num) {
int i = ____①____;
int bound = ____②____;
for (; i <= bound; ++i) {
if (____③____) {
return ____④____;
}
}
return ____⑤____;
}
int main() {
int n;
cin >> n;
if (isSquare(n)) {
cout << n << " is a square number" << endl;
} else {
cout << n << " is not a square number" << endl;
}
return 0;
}
①处应填()
{{ select(1) }}
- 1
- 2
- 3
- 4
2. ②处应填()
{{ select(2) }}
cpp (int)floor(sqrt(num))-1cpp (int)floor(sqrt(num))cpp floor(sqrt(num/2))-1cpp floor(sqrt(num/2))
3. ③处应填()
{{ select(3) }}
cpp num=2*icpp num==2*icpp num=i*icpp num==i*i
4. ④处应填()
{{ select(4) }}
cpp num=2*icpp num==2*icpp truecpp false
5. ⑤处应填()
{{ select(5) }}
cpp num=i*icpp num!=i*icpp truecpp false
相关
在下列比赛中: