Computer Science, asked by aswanthprakkulam, 6 months ago

wap to check if a number is palindrome​

Answers

Answered by Farira
2

•Declare two variables: one stores the given number, and the other stores the reversed number.

•Run the do-while loop until the number of digits in the reversed number are equal to the number of digits in the given number. ...

•Check if the reversed number is equal to the given number.

Answered by anindyaadhikari13
3

Question:-

Write a program to check if a number is palindrome or not.

Program:-

In Java.

import java.util.*;

class Palindrome

{

public static void main(String args[])

{

Scanner sc=new Scanner(System.in);

System.out.print("Enter a number: ");

int n=sc.nextInt();

int x=n, s=0;

while(n!=0)

{

s=s*10+n%10;

n/=10;

}

if(s==x)

System.out.print("Palindrome.");

else

System.out.print("Not Palindrome.");

}

}

In python.

n=int(input("Enter a number: "))

x, s=n, 0

while n!=0:

s=s*10+n%10

n=n//10

if(s==x):

print("Palindrome.")

else:

print("Not Palindrome.")

Similar questions