Q. Write a program to check whether the given number N is Palindrome or Not.



Palindrome Number:- A Palindrome Number is a number that remains same when its digits are reversed or we can say that the Palindrome number is a number that is symmetric.

For Example:- 16461
So as we can see that the number 16461 remains the same when it is reversed so it is a palindrome number.

Palindrome Number Algorithm

START
  Step 1 : Get the number to check for palindrome
  Step 2 : Hold the number in temporary variable
  Step 3 : Reverse the number
  Step 4 : Compare the temporary number with reversed number
  Step 5 : If both numbers are same, print "palindrome number"
  Step 6 : Else print "not palindrome number"
STOP


Program

  • C
  • C++
  • Java
  • Python
  • C#
  • PHP
  • #include <stdio.h>
    int main() {
    int N=12321, rev = 0, rem, new_num;
    new_num = N;
    // reversed integer is stored in reversedN
    while (N != 0) {
    rem = N % 10;
    rev = rev * 10 + rem;
    N /= 10;
    }
    // palindrome if orignalN and reversedN are equal
    if (new_num == rev)
    printf("%d is a palindrome number.", new_num);
    else
    printf("%d is not a palindrome number.", new_num);
    return 0;
    }
    
    #include <iostream>
    using namespace std;
    int main()
    {
    int n, num=12321, digit, rev = 0;
    n = num;
    do
    {
    digit = num % 10;
    rev = (rev * 10) + digit;
    num = num / 10;
    } while (num != 0);
    if (n == rev)
    cout << " The number "<< n<<" is a palindrome.";
    else
    cout << " The number "<< n<<" is not a palindrome.";
    return 0;
    }
    
    public class LFC {
    public static void main(String[] args) {
    int num = 12321, rev = 0, rem, new_num;
    new_num = num;
    // reversed integer is stored in variable 
    while( num != 0 )
    {
    rem = num % 10;
    rev = rev * 10 + rem;
    num  /= 10;
    }
    // palindrome if new_num and rev are equal
    if (new_num == rev)
    System.out.println(new_num + " is a palindrome.");
    else
    System.out.println(new_num + " is not a palindrome.");
    }
    }
    
    n=12321
    temp=n
    rev=0
    while(n>0):
    dig=n%10
    rev=rev*10+dig
    n=n//10
    if(temp==rev):
    print("The number {0} is palindrome number".format(temp))
    else:
    print("The number {0} is palindrome number".format(temp))
    
    using System;  
    public class LFC 
    {  
    public static void Main(string[] args)  
    {  
    int n=12321,r,sum=0,temp;    
    temp=n;      
    while(n>0)      
    {      
    r=n%10;      
    sum=(sum*10)+r;      
    n=n/10;      
    }      
    if(temp==sum)      
    Console.Write("The number "+temp+" is Palindrome number.");      
    else      
    Console.Write("The number "+temp+" is not Palindrome number");     
    }  
    }  
    
    function palindrome($n){  
    $number = $n;  
    $sum = 0;  
    while(floor($number)) {  
    $rem = $number % 10;  
    $sum = $sum * 10 + $rem;  
    $number = $number/10;  
    }  
    return $sum;  
    }  
    $input = 12321;  
    $num = palindrome($input);  
    if($input==$num){  
    echo "The number $input is a Palindrome number";  
    } else {  
    echo "The number $input is not a Palindrome number";  
    }  
    
    #include <stdio.h>
    int main() {
    int N=12321, rev = 0, rem, new_num;
    new_num = N;
    // reversed integer is stored in reversedN
    while (N != 0) {
    rem = N % 10;
    rev = rev * 10 + rem;
    N /= 10;
    }
    // palindrome if orignalN and reversedN are equal
    if (new_num == rev)
    printf("%d is a palindrome number.", new_num);
    else
    printf("%d is not a palindrome number.", new_num);
    return 0;
    }
    

    Output

    The number 12321 is a Palindrome number
    

    Recommended Programs

       Insertion sort program
       Program to check panagram