判断一个数的平方根是否为整数

· · 个人记录

#include <bits/stdc++.h> 
using namespace std;

bool a_test(int x) {
    // 如果大数,int->long long 
    if (sqrt(x) == (int)sqrt(x)) {
        return true;
    } else {
        return false;
    }
}

int main() {

    cout << a_test(10) << endl;  // 0
    cout << a_test(9) << endl;  // 1 

    return 0;
}