Q:

Palindrome number in C

0

Palindrome number in C

 

A palindrome number is one that remains the same on reversal. Some examples are 8, 121, 212, 12321, -454. To check if a number is a palindrome or not, we reverse it and compare it with the original number. If both are the same, it's a palindrome otherwise not.

All Answers

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

#include <stdio.h>
int main()
{
  int n, r = 0, t;

  printf("Enter a number to check if it's a palindrome or not\n");
  scanf("%d", &n);

  t = n;

  while (t != 0)
  {
    r = r * 10;
    r = r + t%10;
    t = t/10;
  }

  if (n == r)
    printf("%d is a palindrome number.\n", n);
  else
    printf("%d isn't a palindrome number.\n", n);

  return 0;
}

output:

Enter a number to check if it's a palindrome or not

2

2 is a palindrome number.

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