Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

leetcode problem palindrome.cpp #59

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions palindrome.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#include<iostream>

using namespace std;

void case1(int x)
{ x=121;
cout<<"for positive integers : "<<x<<endl;
}
void case2(int x)
{ x=-121;
cout<<"for negative integers : "<<x<<endl;
}
void case3(int x)
{ x=10;
cout<<"for integers end with zero: "<<x<<endl;
}

bool isPalindrome(int x) {
if(x < 0)
{
return false;
}
long n = x;
long Num = 0, rem;
while(x != 0)
{
rem = x%10;
Num = (Num*10)+rem;
x /= 10;
}

if(Num == n)
{
return true;
}
return false;
}

int main()
{
int x,c,n;
case1(x);
// cout<<isPalindrome(x);
if(c==0)
{cout<<"false"<<endl;}
else{cout<<"true"<<endl;}
case2(x);
c=isPalindrome(x);
if(c==0)
{cout<<"false"<<endl;}
else{cout<<"true"<<endl;}
case3(x);
c=isPalindrome(x);
if(c==0)
{cout<<"false"<<endl;}
else{cout<<"true"<<endl;}
return 0;
}