Q:

C PROGRAM EXAMPLE FOR PALINDROME

0

C PROGRAM EXAMPLE FOR PALINDROME:

 

What is palindrome?

  • When a number or word or a phrase or a sequence of characters which resembles the same while reading them from backward are called palindrome.
  • Palindrome examples: 2882, madam, noon, level.
  • The above examples resemble as same while reading them from backward also. If you read number “2882” from backward, it is same as “2882”. If you read the word “madam” from backward, it is same as “madam”

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include <stdio.h>
int main()
{
   int number, t, rev=0, rmndr;
 
   printf("Please enter a number to check Palindrome : ");
   scanf("%d",&number);
   printf("\nEntered number: %d", number);
   t = number;
 
   while (number > 0)
   {
      rmndr = number%10;
      rev = rev*10 + rmndr;
      number = number/10;
   }
   printf("\nReversed number: %d", rev);
 
   if(t == rev)
   {
      printf("\nEntered number %d is a palindrome", t);
   }
   else
   {
      printf("\nEntered number %d is not a palindrome", t);
   }
   return 0;
}

OUTPUT

Please enter a number to check Palindrome : 656
Entered number: 656
Reversed number: 656
Entered number 656 is a palindrome

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now