-
Notifications
You must be signed in to change notification settings - Fork 96
/
Copy pathpalindrome.cpp
58 lines (53 loc) · 1.06 KB
/
palindrome.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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;
}