Computer Science, asked by Rituangel, 1 year ago

Write a c++ code for palindrome

Answers

Answered by Sarthak701
2
#include<iostream.h>
#include<conio.h>
void main()
{
int a,no,b,temp=0;
clrscr();
cout<<"Enter any num: ";
cin>>no;
b=no;
while(no>0)
{
a=no%10;
no=no/10;
temp=temp*10+a;
}
if(temp==b)
{
cout<<"Palindrome"; }
else
{
cout<<"Not Palindrome";
}
getch();
}

Rituangel: Thanx
Sarthak701: wlcm
Answered by Pravallika2411
1
I can give u logic
syntax can be done any way
Here number should be equal to reverse
so first find reverse
loop and also we need to use a temporary variable

int temporary= number;
int reverse= 0;

for(temporary>0) {
int remainder = temporary %10;
reverse = reverse * 10 + remainder;
temporary = temporary / 10;
}
if (num == reverse) {
printf ("It is a palindrome");
} else {
printf ("Not a palindrome");
}

This is logic u can use in any language with that syntax
Hope it helps
please comment if you have any doubt



Rituangel: Thanx
Rituangel: Tell me how the condition is working plzz
Pravallika2411: first number is given to temporary variable and then we find last digit of number and reverse of it by finding first digit
Rituangel: Thank u
Rituangel: I got it
Pravallika2411: welcome
Similar questions