C program to check the number is palindrome or not - My CS Tutorial - My CS Tutorial

Breaking

Programming languages full tutorial and programs, exam papers, visual basic( Vb.net ), information of new technologies and more....

Tuesday, November 26, 2019

C program to check the number is palindrome or not - My CS Tutorial

In this tutorial,we will learn how to write a program that check given number is palindrome or not.




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

7645



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