Home C Language Basic C Programs Palindrome in C

Palindrome in C

## Write a C Program to Find whether the given number palindrome or not.

#include<stdio.h>

int main()

{

int n,s=0,a,t; //’n’ for user defined integer,’s’ for store resultant ,’t’ for temporary, ‘a’ for calculations.

printf(“Enter a value : “);

t=n;

while(t>0) //If entered number is greater than zero then only loop will execute

{

a=t%10; //pick last digit from temporary variable.

s=(s*10)+a; //adding ‘a’ to ‘s’ as next digit to the existed number in ‘s’

t=t/10; //removing last digit from ‘t’

}

if(n==s)

printf(“Given number is palindrome\n”);

else

printf(“Given number is not palindrome\n”);

return 0;

}

Output:

i) Enter a value : 4774

Given number is palindrome

ii) Enter a value : 25725

Given number is not palindrome

For improvement of your coding skills we give some tasks along this. If you solve this tasks and send to our email (onlineexamshubteam@gmail.com) with your details. We will display your details(like Name, City, college, photo) in our site.

Task: Write a C program to generate palindrome numbers between ‘m’ & ‘n’ natural numbers.

For example user entered 163 & 193 then output will be: 171 181 191