-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPalindromeOfaNumber.cpp
More file actions
60 lines (52 loc) · 1.31 KB
/
PalindromeOfaNumber.cpp
File metadata and controls
60 lines (52 loc) · 1.31 KB
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
59
60
#include <iostream>
using namespace std;
// not true in 0123210 case-------------
// bool PalindromeNumber(int num) {
// int original = num; // Store the original number to compare later
// int reversed = 0; // This will hold the reversed number
// while (num > 0) {
// int digit = num % 10; // Get the last digit
// reversed = reversed * 10 + digit; // Build the reversed number
// num /= 10; // Remove the last digit from num
// }
// return original == reversed; // Compare original number with reversed number
// }
// int main() {
// int num;
// cout << "Enter number: ";
// cin >> num;
// if (PalindromeNumber(num)) {
// cout << "True"; // The number is a palindrome
// }
// else {
// cout << "False"; // The number is not a palindrome
// }
// }
// Enter number: 0123210
// False
// true-------------
bool PalindromeNum(const string& num){
int l = 0;
int r = num.size()-1;
while(l < r){
if (num[l] != num[r]){
return false;
}
l++;
r--;
}
return true;
}
int main(){
string num;
cout << "enter number: ";
cin>>num;
if(PalindromeNum(num)){
cout << "True";
}
else{
cout << "False";
}
}
// enter number: 011232110
// True