fork download
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5. bool isPerfectSquare(int num) {
  6. int n = sqrt(num);
  7. return (n * n == num);
  8. }
  9.  
  10. int main() {
  11. int num1=16;
  12. int num2=14;
  13. cout << "Is " << num1 <<" perfect square ? " << (isPerfectSquare
  14. (num1) ? "Yes" : "No") << endl;
  15. cout << "Is " << num2 <<" perfect square ? " << (isPerfectSquare
  16. (num2) ? "Yes" : "No") << endl;
  17. return 0;
  18. }
  19.  
Success #stdin #stdout 0.01s 5284KB
stdin
Standard input is empty
stdout
Is 16 perfect square ? Yes
Is 14 perfect square ? No