C program to reverse a given integer number and check whether it is a palindrome. Output the given numbers with suitable message

by Nideesh C on April 12, 2011 · 0 comments

in C Programming




/* C program to reverse a given integer number and check whether it is a palindrome. Output the given numbers with suitable message */

#include <stdio.h>
#include <conio.h>

void main()
{
int   num, temp, digit, rev = 0;

clrscr();

printf(“Enter an integer\n”);
scanf(“%d”, &num);

temp = num;        /* original number is stored at temp */

while(num > 0)
{
digit = num % 10;
rev = rev * 10 + digit;
num /= 10;
}

printf(“Given number is = %d\n”, temp);
printf(“Its reverse is  = %d\n”, rev);

if(temp == rev )
printf(“Number is a palindrome\n”);
else
printf(“Number is not a palindrome\n”);
}
/*————————
Output
RUN 1
Enter an integer
12321
Given number is = 12321
Its reverse is  = 12321
Number is a palindrome

RUN 2
Enter an integer
3456
Given number is = 3456
Its reverse is  = 6543
Number is not a palindrome
———————————–*/

Not Satisfied ? Just search & get the result

Related Posts Plugin for WordPress, Blogger...
Be Sociable, Share!

Related posts:

  1. C program to check whether a given integer number is positive or negative
  2. C program to check whether a given integer is odd or even
  3. C program to find the sum of odd numbers and sum of even numbers from 1 to N. Output the computed sums on two different lines with suitable headings
  4. Sample – Program to enter an integer and output it in the reversed form.
  5. Sample – Program to enter an integer and print its total value based on the formula ‘x – 1/3!x3 + 1/5!x5 – 1/7!x7 + 1/9!x9′.

Leave a Comment

Previous post:

Next post: