I have a working code that takes a number and its square to check the reverse of the number and see if it matches a reverse of the original square.
An output answer that would be correct for example:Code:#include<iostream> #include<conio.h> using namespace std; int reverse(int i) { int temp=i, sum=0; while(temp) { sum*=10; sum += temp%10; temp/=10; } return sum; } int square(int i) { return i*i; } void main() { for(int i=1; i<10001; i++) { if(i>9) { if(i!=reverse(i)) { if(square(reverse(i))==reverse(square(i))) { cout<<"The number "<<i<<" squares to "<<square(i)<<endl; cout<<"The number "<<reverse(i)<<" squares to "<<square(reverse(i))<<endl; cout<<endl; } } } } getch(); }
The number 12 squares to 144
The number 21 squares to 441
However, I want to remove answers with leading zeroes that are included in the output, such like:
The number 20 squares to 400
The number 2 squares to 4