forked from riyaaa04/cpp20
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path38.cpp
More file actions
27 lines (22 loc) · 648 Bytes
/
38.cpp
File metadata and controls
27 lines (22 loc) · 648 Bytes
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
#include <iostream>
using namespace std;
int main() {
int num, originalNum, reversedNum = 0, remainder;
// Input the number
cout << "Enter a number: ";
cin >> num;
originalNum = num;
// Reverse the number using nested loops
while (num > 0) {
remainder = num % 10;
reversedNum = reversedNum * 10 + remainder;
num /= 10;
}
// Check if the original number is equal to its reversed version
if (originalNum == reversedNum) {
cout << originalNum << " is a palindrome." << endl;
} else {
cout << originalNum << " is not a palindrome." << endl;
}
return 0;
}