fork download
  1. #include <iostream>
  2. #include <math.h>
  3. using namespace std;
  4. bool checkAuto(int a){
  5. if(a < 0) a = -a;
  6. int squareNum = a*a;
  7. int temp = a;
  8. int count = 0; // count of digit of a
  9. int lastNum = 0;
  10. while(temp > 0){
  11. count++;
  12. temp = temp/10;
  13. }
  14. int lastDigit = (squareNum)%(int(pow(10, count)));
  15. if(lastDigit == a) return true;
  16. else return false;
  17. }
  18. int main() {
  19. int num = -4;
  20. if(checkAuto(num)) cout << "Automorphic";
  21. else cout << "Not Automorphic";
  22. cout << endl;
  23. return 0;
  24. }
  25.  
Success #stdin #stdout 0.01s 5432KB
stdin
Standard input is empty
stdout
Not Automorphic