Adam Number or Not
A number is said to be an Adam number if the reverse of the square of the number is equal to the square of the reversed number.for example 12 is a adam number because the reverse of the square of 12 is 144 which is 441 and square of the reverse of 12 is the square of the 21 which is also 441
Sample input : 12
Sample output : adam number
Sample input : 14
Sample output : not an adam number
OUTPUT :
Sample input : 12
Sample output : adam number
Sample input : 14
Sample output : not an adam number
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | #include<iostream> #include<cstring> #include<algorithm> using namespace std; int main() { string num,rev; int sq_1,sq_2; cout<<"Enter the number "; cin>>num; //num=12 rev=num; reverse(rev.begin(),rev.end()); //rev=21 sq_1=stoi(num)*stoi(num); //stoi-string to integer //12*12=144 sq_2=stoi(rev)*stoi(rev);//21*21=441 num=to_string(sq_1); //convert number to string rev=to_string(sq_2); reverse(rev.begin(),rev.end());//441-reversed to 144 if(num==rev) //144==144 { cout<<"Given number is an adam number"; } else { cout<<"Given number is not an adam number"; } } |
OUTPUT :
0 comments