Users Online

· Guests Online: 164

· Members Online: 0

· Total Members: 188
· Newest Member: meenachowdary055

Forum Threads

Newest Threads
No Threads created
Hottest Threads
No Threads created

Latest Articles

31 C Program to Reverse a Number & Check if it is a Palindrome

This C Program reverses a number & checks if it is a palindrome or not. First it reverses a number. Then it checks if given number and reversed numbers are equal. If they are equal, then its a palindrome.
Here is source code of the C program to reverse a number & checks it is a palindrome or not. The C program is successfully compiled and run on a Linux system. The program output is also shown below.

/*
* C program to reverse a given integer number and check
* whether it is a palindrome. Display the given number
* with appropriate message
*/
#include <stdio.h>

void main()
{
int num, temp, remainder, reverse = 0;

printf("Enter an integer \n");
scanf("%d", &num);
/* original number is stored at temp */
temp = num;
while (num > 0)
{
remainder = num % 10;
reverse = reverse * 10 + remainder;
num /= 10;
}
printf("Given number is = %d\n", temp);
printf("Its reverse is = %d\n", reverse);
if (temp == reverse)
printf("Number is a palindrome \n");
else
printf("Number is not a palindrome \n");
}

$ cc pgm13.c
$ a.out
Enter an integer
6789
Given number is = 6789
Its reverse is = 9876
Number is not a palindrome

$ a.out
Enter an integer
58085
Given number is = 58085
Its reverse is = 58085
Number i

Comments

No Comments have been Posted.

Post Comment

Please Login to Post a Comment.

Ratings

Rating is available to Members only.

Please login or register to vote.

No Ratings have been Posted.
Render time: 1.03 seconds
10,807,085 unique visits