Showing posts with label to check whether a number is a palindrome or not. Show all posts
Showing posts with label to check whether a number is a palindrome or not. Show all posts

Thursday, 14 May 2015

Python program to check whether a number is Palindrome or not


This is a Python program which checks whether a number is palindrome or not .
Generally a number is said to be a palindrome number if its reverse is same as the original number .

For Example : 121 is a palindrome as its reverse is also 121 where as , 231 is not a palindrome as its reverse is 132 .





PROGRAM :
num = int(input('Enter any number : '))
if str(num) == str(num)[::-1]:
    print("Given number is a PALINDROME number")
else:
    print("Given number is NOT a palindrome number")


OUTPUT : 
Python - Palindorme or not

Python - Palindorme or not



Similar Programs : 
C program to check whether a number is Palindrome or not
Cpp program to check whether a number is Palindrome or not
Java program to check whether a number is Palindrome or not

Monday, 5 January 2015

Java Program to check whether a number is Palindrome number or not




This is a Java program which checks whether a number is palindrome or not .
Generally a number is said to be a palindrome number if its reverse is same as the original number .

For Example : 121 is a palindrome as its reverse is also 121 where as , 231 is not a palindrome as its reverse is 132 .




PROGRAM :

package codingcorner.in;

import java.util.Scanner;

public class Palindrome {
 public static void main(String[] args) {
  int number, remainder, reverse = 0, num;
  Scanner scan = new Scanner(System.in);
  System.out.println("Enter a number :\t");
  number = scan.nextInt();
  scan.close();
  num = number;
  while (number != 0) {
   remainder = number % 10;
   reverse = reverse * 10 + remainder;
   number = number / 10;
  }
  if (reverse == num)
   System.out.println(num + "  is Palindrome");
  else
   System.out.println(num + "  is not a Palindrome");
 }
}

OUTPUT :

Saturday, 3 January 2015

Cpp Program to check whether a number is Palindrome number or not



This is a Cpp program which checks whether a number is palindrome or not .
Generally a number is said to be a palindrome number if its reverse is same as the original number .

For Example : 121 is a palindrome as its reverse is also 121 where as , 231 is not a palindrome as its reverse is 132 .


PROGRAM :


#include <iostream>

using namespace std;

int main()
{
    int n,copy_num,remainder,reverse = 0;
    cout << "Enter a number : \t" ;
    cin >> n;
    copy_num = n;

    while(n)
    {
        remainder = n%10;
        reverse = reverse*10+remainder;
        n=n/10;
    }
    if(reverse == copy_num)
        cout << copy_num <<" is a PALINDROME "<< endl;
    else
        cout << copy_num << "  is not a palindrome " << endl;
    return 0;
}

OUTPUT :



Saturday, 27 December 2014

C Program to check whether a number is Palindrome number or not

This is a C program which checks whether a number is palindrome or not .
Generally a number is said to be a palindrome number if its reverse is same as the original number .

For Example : 121 is a palindrome as its reverse is also 121 where as , 231 is not a palindrome as its reverse is 132 .



PROGRAM :


#include <stdio.h>
#include <stdlib.h>
int main()
{
    int number,remainder,reverse=0,num;
    printf("Enter a number :\t");
    scanf("%d",&number);
    num=number;
    while(number)
    {
        remainder = number%10;
        reverse= reverse*10+remainder;
        number=number/10;
    }
    if(reverse == num)
    printf("%d is Palindrome",num);
    else
        printf("%d is not a Palindrome",num);
    return 0;
}
OUTPUT :

C - Palindrome or not