Write a c++ code for palindrome
Answers
Answered by
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();
}
#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
Answered by
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
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
Similar questions