Program to check whether the number is palindrome or not.

Here, we have a basic program example to check if the number is palindrome or not using different languages. A palindrome is a word, number, phrase, or other sequence of symbols that reads the same backwards as forwards, such as “madam”. This program is created in c language, c++, Java, and Python.

Code to check if the number is palindrome in C language

#include <stdio.h>
int main() {
  int n, rev = 0, r, org;
    printf("Enter an integer: ");
    scanf("%d", &n);
    org = n;
    while (n != 0) {
        r = n % 10;
        rev = rev * 10 + r;
        n /= 10;
    }
    if (org == rev)
        printf("%d is a palindrome.", org);
    else
        printf("%d is not a palindrome.", org);

    return 0;
}

Code to check if the number is palindrome in C++ language

#include <iostream>
using namespace std;
int main() {
    int n, rev = 0, r, org;
    cout<<"Enter an integer: ";
    cin>>n;
    org = n;
    while (n != 0) {
        r = n % 10;
        rev = rev * 10 + r;
        n /= 10;
    }
    if (org == rev)
        cout<<org<<" is a palindrome.";
    else
        cout<<org<<" is not a palindrome.";

    return 0;
}

Code to check if the number is palindrome in Python language

n = int(input("Enter an integer: "))
rev = 0
org = n
while (n != 0):
   r = n % 10
   rev = rev * 10 + r
   n = n // 10
if (org == rev):
   print(org," is a palindrome.")
else:
   print(org," is not a palindrome.")

Code to check if the number is palindrome in Java language

import java.util.*;
public class palindrome {
    public static void main(String[] args) {     
       int n, rev = 0, r, org;
       
	System.out.println("Enter a positive integer:  ");
        Scanner s=new Scanner(System.in);
        n = s.nextInt();

       org = n;
       while (n != 0) {
         r = n % 10;
         rev = rev * 10 + r;
         n /= 10;
      }
      if (org == rev)
        System.out.println(org + " is a palindrome.");
      else
        System.out.println(org + " is not a palindrome.");
      }