Header Ads

WAP to Check whether the given Number is Palindrome or Not in C - 50

This program check's whether the given number is Palindrome or Not, and prints the Reverse order of the Number.

 Program Code:

/* Program to check whether the given number is Palindrome or Not! */

#include <stdio.h>
int main() 
{
        int val, num, rem, rev = 0;

        /* get the input number from user */
        printf("Enter a Number : ");
        scanf("%d", &num);
        val = num;

        /* find the reverse for the given input */
        while (val > 0) 
 {
                rem = val % 10;
                rev = (rev * 10) + rem;
                val = val / 10;
        }
        printf("Given Number is '%d' and it's, Reverse order is '%d'.\n", num, rev);

        /* if the reverse of a number equals itself - palindrome */
        if (num == rev)
                printf("Result: The Given Number is Palindrome!\n");
        else
                printf("Result: Given number is Not a Palindrome!\n");
        return 0; 
  }

Program Ouput:

 

No comments