Programming
Pallindrome

Question Description

Program for Pallindrome NUmber

Student has agreed that all tutoring, explanations, and answers provided by the tutor will be used to help in the learning process and in accordance with Studypool's honor code & terms of service.

Final Answer

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. 



Duke University

Anonymous
Excellent! Definitely coming back for more study materials.

Studypool
4.7
Trustpilot
4.5
Sitejabber
4.4