Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
177 views2 pages

C Program To Check Whether A Number Is Palindrome or Not

This document discusses how to check if a number is a palindrome in C programming. It explains that a palindrome number is the same when reversed, like 121. It provides the logic that to check if a number is a palindrome, the program must find the reverse of the given number and compare it to the original. The document includes a C program that takes user input, finds the reverse, and prints whether the number is a palindrome or not using an if/else statement.

Uploaded by

Gas dela Rosa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
177 views2 pages

C Program To Check Whether A Number Is Palindrome or Not

This document discusses how to check if a number is a palindrome in C programming. It explains that a palindrome number is the same when reversed, like 121. It provides the logic that to check if a number is a palindrome, the program must find the reverse of the given number and compare it to the original. The document includes a C program that takes user input, finds the reverse, and prints whether the number is a palindrome or not using an if/else statement.

Uploaded by

Gas dela Rosa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

Write a C program to enter any number and check whether given number is palindrome

or not using for loop. How to check whether a number is palindrome or not in C
programming. C program for palindrome numbers.

Example:
Input number: 121
Output: 121 is Palindrome

Required knowledge
Basic C programming, If else, For loop

Palindrome numbers
Palindrome numbers are such number which when reversed are equal to the original
number.
For example: 121
Reverse of 121 is also equal to 121. Hence 121 is a palindrome number.

Logic to check palindrome numbers


From the definition of the palindrome numbers it must be clear to all that in-order
to check whether a number is palindrome or not we must find the reverse of the
number. After retrieving the reverse of number we just need to make a conditional
check that whether the given number is equal to its reverse or not. If the given
number and its reverse are same then the number is palindrome otherwise not.

Program to check palindrome number

/**
* C program to check whether a number is palindrome or not
*/

#include <stdio.h>

int main()
{
int n, num, rev = 0;

/* Reads a number from user */


printf("Enter any number to check palindrome: ");
scanf("%d", &n);

num = n; //Copies original value to num.

/* Finds reverse of n and stores in rev */


while(n!=0)
{
rev = (rev * 10) + (n % 10);
n = n/10;
}

/* Check if reverse is equal to original num or not */


if(rev==num)
{
printf("%d is palindrome.", num);
}
else
{
printf("%d is not palindrome.", num);
}
return 0;
}

You might also like