A Palindrome number is a number that remains the same when its digits are reversed. In other words, if you read the number from left to right or right to left, it will be the same. Palindrome numbers are commonly used in computer programming and number theory, and they can be a fun topic for math enthusiasts to explore.
Explanation: 151 on reversing is 151 which is the same
For example: –
151 is a Palindrome Number
1243 is not a Palindrome Number
Explanation: 1243 on reversing is 3421 which is not the same
There are two ways to determine if the input number is palindrome or not
- Using while-loop
- Using Recursion
#include<stdio.h>
void main()
{
int n,n2,s=0,t;
printf("Enter the number ");
scanf("%d",&n);
n2=n;
while(n2!=0)
{
t=n2%10;
s=s*10+t;
n2=n2/10;
}
if(s==n)
printf("It is a Palindrome number");
else
printf("It is not a Palindrome number");
}
#include<iostream>
using namespace std;
main()
{
int n,n1,d,a,s=0;
cout<<"Enter a number: ";
cin>>n;
n1=n;
while(n1!=0){
a=n1%10;
s=s*10+a;
n1=n1/10;
}
if(s==n){
cout<<"Palindrome number";
}
else{
cout<<"Not Palindrome number";
}
}
import java.util.*;
public class PalindromeNo
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int a=n;
int b=0,r=0;
while(n!=0)
{
b=n%10;
r=r*10+b;
n=n/10;
}
if(r==a)
{
System.out.println("Palindrome number");
}
else
{
System.out.println("Not Palindrome number");
}
}
}
n=int(input("Enter a number"))
n1=n
s=0
while (n1!=0):
t=n1%10
s=s*10+t
n1//=10
print(s)
if s==n:
print("Palindrome number")
else:
print("Not Palindrome number")

0 Comments