Write a program to identify if the number is Palindrome or not

15 May 2022

Write a program to identify if the number is Palindrome or not


If you are from 2023 batch student, Join our Telegram group for placement preparation and coming placement drive updates : https://t.me/talentbattle2023

Description

Get a number as input from the user and check whether that number is a Palindrome or not.

Input

121

Output

Palindrome

Input

34

Output

Not a Palindrome

C Program

#include <stdio.h>

int main()

{

    int  num,rem,rev=0,copy;

    printf("Enter a number: ");

    scanf("%d",&num);

    copy=num;

    while(num!=0)

    {

        rem=num%10;

        rev=rev*10+rem;

        num=num/10;

    }

    if(rev==copy)

    printf("Palindrome number");

    else

    printf("Not a Palindrome number");

    return 0;

}

C++ Program

#include <iostream>

using namespace std;

int main()

{

    int  num,rem,rev=0,copy;

    cout<<"Enter a number: ";

    cin>>num;

    copy=num;

    while(num!=0)

    {

        rem=num%10;

        rev=rev*10+rem;

        num=num/10;

    }

    if(rev==copy)

    cout<<"Palindrome number";

    else

    cout<<"Not a Palindrome number";

    return 0;

}

Java 

import java.util.Scanner;

public class Main

{

public static void main(String[] args) {

Scanner sc=new Scanner(System.in); 

System.out.println("Enter a number");

int num=sc.nextInt();

int rem,rev=0;

int copy=num;

        while(num!=0)

        {

            rem=num%10;

            rev=rev*10+rem;

            num=num/10;

        }

    if(rev==copy)

    System.out.println("Palindrome number");

    else

    System.out.println("Not a Palindrome number");

 

}

}

Python

num=int(input("Enter a number: "))

rem=0

rev=0

copy=num

while num!=0:

    rem=num%10

    rev=rev*10+rem

    num=num//10

if(copy==rev):

    print("Palindrome")

else:

    print("Not a palindrome")


If you are from 2023 batch student, Join our Telegram group for placement preparation and coming placement drive updates : https://t.me/talentbattle2023
Related Articles

Ask Us Anything !