Skip to content
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;
}