0

The output code is stuck!

#include <iostream> #include <string> #include <sstream> using namespace std; string isAutomorphic(){ string a; int num; int is; int c; string f; string r; string x; stringstream stream; cin >> a; cout << "Your number: " << a << endl; stream << a; stream >> num; int b = num * num; cout << "Squared: " << b << endl; stream.str(""); stream << b; stream >> x; int z = num; is = x.find_last_of(z); stream.str(""); stream << num; stream >> r; if (num != (r.size() - (r.size() - is))){ f = "No, it is not an automorphic number."; } else if (num == (r.size() - (r.size() - is))){ f = "Yes, it is an automorphic number."; } stream.str(""); return f; } int main() { cout << isAutomorphic() << endl; return 0; } The code is stuck on “No, it is not an automorphic number”. https://code.sololearn.com/c8q1auNCtlWZ/?ref=app

17th Jun 2018, 4:33 AM
mei
mei - avatar
1 Respuesta
0
Hi, I'm not sure of your code but, #include <bits/stdc++.h> using namespace std; int main(){ int x, z, digit; long int y; cin >> x; // except 0, 1 z = x; y = x*x; digit = 0; while(z>0){ z = z/10; ++digit; } cout << boolalpha; // 0-> false, 1-> true cout << ((y%pow(10,digit))==x) << '\n' ; return 0; }
9th Dec 2018, 9:02 PM
LiquidX
LiquidX - avatar