Pallindrome

Programming
Tutor: None Selected Time limit: 1 Day

Program for Pallindrome NUmber
Nov 30th, -0001

C Program to Check Whether a Number is Palindrome or Not

This program takes an integer from user and that integer is reversed. If the reversed integer is equal to the integer entered by user then, that number is a palindrome if not that number is not a palindrome.

C Program to Check Palindrome Number

/* C program to check whether a number is palindrome or not */#include<stdio.h>int main(){int n, reverse=0, rem,temp;
  printf("Enter an integer: ");
  scanf("%d",&n);
  temp=n;while(temp!=0){
     rem=temp%10;
     reverse=reverse*10+rem;
     temp/=10;}/* Checking if number entered by user and it's reverse number is equal. */if(reverse==n)  
      printf("%d is a palindrome.",n);else
      printf("%d is not a palindrome.",n);return0;}

Output

Enter an integer: 12321
12321 is a palindrome.


Java program to find whether no. is palindrome or not

package testing;
import java.util.Scanner;

/**
 * Java program to check if number is palindrome or not.
 * A number is called palindrome if number and its reverse is equal
 * This Java program can also be used to reverse a number in Java
 */
public class NoClassDefFoundErrorDueToStaticInitFailure {

   public static void main(String args[]){
       
       System.out.println("Please Enter a number : ");
       int palindrome = new Scanner(System.in).nextInt();
       
       if(isPalindrome(palindrome)){
           System.out.println("Number : " + palindrome + " is a palindrome");
       }else{
           System.out.println("Number : " + palindrome + " is not a palindrome");
       }     
       
   }
 
   /*
     * Java method to check if number is palindrome or not
     */

   public static boolean isPalindrome(int number) {
       int palindrome = number; // copied number into variable
       int reverse = 0;

       while (palindrome != 0) {
           int remainder = palindrome % 10;
            reverse = reverse * 10 + remainder;
            palindrome = palindrome / 10;
       }

       // if original and reverse of number is equal means
       // number is palindrome in Java
       if (number == reverse) {
           return true;
       }
       return false;
   }

}

Output:
Please Enter a number : 
123
Number : 123 is not a palindrome
Please Enter a number : 
121
Number : 123 is a palindrome

Please rate this answer as the best answer if you are satisfied as this is how I receive credit for my work. Thank you. 



May 31st, 2013

Studypool's Notebank makes it easy to buy and sell old notes, study guides, reviews, etc.
Click to visit
The Notebank
...
Nov 30th, -0001
...
Nov 30th, -0001
Mar 29th, 2017
check_circle
Mark as Final Answer
check_circle
Unmark as Final Answer
check_circle
Final Answer

Secure Information

Content will be erased after question is completed.

check_circle
Final Answer