Palindrome number in C

Write A Program To Check a Number Is Palindrome Or Not ?

A palindrome number is one that remains the same on reversal. Some examples are 121,212,515. 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.

C program for palindrome number


#include<stdio.h>
#include<conio.h>
void 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);
  getch();
}
Function to check palindrome number
int check_palindrome(int n) {
  int t, r = 0;
  t = n;
  while (!= 0) {
    r = r * 10;
    r = r + t%10;
    t = t/10;
  }
  if (== r)
    return 1;
  else
    return 0;
}

No comments:

Post a Comment