Write a Program in C++ & Python to find whether a number is a palindrome or not

Posted in

Vinay Khatri
Last updated on June 8, 2022

    This code checks whether the entered number is a palindrome or not. A palindrome number is a unique number whose reverse is equal to it. For example, 11, 111, 121, 131… are palindrome numbers. C++:

    #include<iostream.h>
    #include< conio.h>
    #include<stdio.h>
    #include<math.h>
    void main()
    {
    clrscr();
    int num, temp,l,m=0;
    cout<<"Enter a number: ";
    cin>>num;
    temp= num;
    while(num!=0)
    { l = n%10;
    m = l+(m*10);
    num =num/10;
    }
    if(temp==m)
    cout<<"It’s a palindrome";
    else
    cout<<"It’s not a palindrome";
    getch();
    }

    Output:

    Enter a Number: 1111
    It’s a palindrome

    Python:

    num =int(input("Enter a Number: "))
    temp= num
    m=0
    while num!=0:
        l= num%10
        m=l+(m*10)
        num=num//10
    
    if temp== m:
        print("It’s a palindrome")
    else:
        print("It’s not a palindrome")

    Output:

    Enter a Number: 1111
    It’s a palindrome

    People are also reading:

    Leave a Comment on this Post

    0 Comments