A palindrome is a number or a text phrase that reads the sam

A palindrome is a number or a text phrase that reads the same backward as forward. For example, each of the following five-digit integers is a palindrome. 12321, 55555, 45554 and 11611. Write a program that reads a five-digit integer and determines whether or not it\'s a palindrome.

Solution

C program to determine if a number is palindrome or not:

#include<stdio.h>
int main()
{
   long input;
   long reverse = 0;
   long temp;
   printf(\"Enter the input number: \");
   scanf(\"%ld\",&input); //Read input from user
   temp = input;         //Save input to another variable
   while(temp > 0) {
      // extract last digit from temp and add it as last digit in reverse
      // by moving existing digits one position towards left
      reverse = reverse*10 + (temp%10);
      temp = temp/10; // removes last digit and move other digits to right
   }
   if (input == reverse) // check if input and reverse are same
      printf(\"Number is a palindrome\ \");
   else
      printf(\"Number is not palindrome\ \");
   return 0;
}

 A palindrome is a number or a text phrase that reads the same backward as forward. For example, each of the following five-digit integers is a palindrome. 1232

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site