(adsbygoogle = window.adsbygoogle || []).push({ google_ad_client: "ca-pub-2960223314593660", enable_page_level_ads: true }); Program to check whether a number is palindrome or not. - TecGlance

Header Ads

Program to check whether a number is palindrome or not.


Algorithm:
Step 1: Read a number, num
Step 2: Assign rev=0
Step 3: Assign temp=num

Step 4: Repeat steps 5,6&7 until num=0 reaches

Step 5: Compute rem=num%10

Step 6: Compute rev=rev*10+rem

Step 7: Compute num=num/10

Step 8: If rev==temp goto step 9 else goto steo 10

Step 9: Print number entered is a palindrome

Step 10: Print the number entered is not a palindrome

Step 11: Stop

Flowchart:

Program code:
num=int(input('Enter a number'))
rev=0
temp=num
while num>0:
    rem=num%10
    rev=rev*10+rem
    num=num/10
if rev==temp:
    print 'The number is a palindrome'
else:
    print 'The number is not a palindrome'

   

No comments

Powered by Blogger.