In this tutorial,we will learn how to write a program that check given number is palindrome or not.
1234321
7645
C program code
#include<stdio.h>
#include<conio.h>
void main()
{
int dummy,n,rev=0,x;
printf("\n Enter a number:\n ");
scanf("%d",&n);
dummy=n;
while(n>0)
{
x=n%10;
rev=rev*10+x;
n=n/10;
}
if(dummy==rev)
printf("\n The given number %d is a palindrome.\n ",rev);
else
printf("\n The given number %d is not a palindrome.\n",rev);
getch();
}
OUTPUT 1:
OUTPUT 2:
In first output,the value of number is 1234321
The given number is palindrome because its reverse is same
1234321
In second output,the value of number is 5467
The given number is not palindrome because its reverse is not same
Please share this post and blog link with your friends.For more programs use this blog.
If you have any problem, please comment in comment box, subscribe this blog for notifications of new post on your email and follow this blog.
Created by-- HARSH CHAUHAN
No comments:
Post a Comment