Adam Number
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 reverse of the number. For example, 12 is an Adam
number because the reverse of the square of 12 is the reverse of 144,
which is 441, and the square of the reverse of 12 is the square of 21,
which is also 441.
Write an Algorithm and the subsequent Python code
to check whether the given number is an Adam number or not.
Write a function to reverse a number
Input Format:
The first line will contain the number.
Output Format:
Print Adam number or Not an Adam number
Input:
The
number n
Processing:
def reverse(number):
rev_num = ''
temp = number
while temp:
rev_num = rev_num + str(temp%10)
temp = temp//10
rev_num = int(rev_num)
return rev_num
rev_num = ''
temp = number
while temp:
rev_num = rev_num + str(temp%10)
temp = temp//10
rev_num = int(rev_num)
return rev_num
Output:
Display
whether the number is an Adam Number or not
Program:
def reverse(number):
rev_num = ''
temp = number
while temp:
rev_num = rev_num + str(temp%10)
temp = temp//10
rev_num = int(rev_num)
return rev_num
n = int(input())
if reverse(n**2) == (reverse(n)**2):
print('Adam number')
else:
print('Not an Adam number')
rev_num = ''
temp = number
while temp:
rev_num = rev_num + str(temp%10)
temp = temp//10
rev_num = int(rev_num)
return rev_num
n = int(input())
if reverse(n**2) == (reverse(n)**2):
print('Adam number')
else:
print('Not an Adam number')
Algorithm:
Step1.
Define the reverse function which has one parameter as number
Step1.1
assign rev_num as an empty string
Step1.2
assign temp as number
Step1.3
repeat till is not equal to zero
Step1.3.1
assign rev_num as the sum of rev_num and the remainder obtained when temp is
divided by 10 which is converted into a string
Step1.3.2
let temp be temp divided by 10
Step1.4
get the number n
Step1.5
check if reverse of square of n is equal to reverse of n and take the square if
true display adam number else display not an adam number.
Step1.6
End
this code is not working
ReplyDeleteinput given-14
output-not an adam number
but i m getting adam number
I updated the code...thanks for pointing it out..
Delete