#include <iostream>
#include <cmath>
const int length = 6;
int main()
{
int numb;
std::cout << "Input number: ";
std::cin >> numb;
if (!(numb >= (int)pow(10, length - 1) && numb < (int)pow(10, length))) {
std::cout << "\nInput error!";
}
else {
bool isPal = true;
for (int i = 0; i < length / 2; i++) {
if (((numb % (int)pow(10, i + 1) - numb % (int)pow(10, i)) / (int)pow(10, i)) != (numb / (int)pow(10, length - 1 - i) - 10 * (numb / (int)pow(10, length - i)))) {
isPal = false;
std::cout << "\nIt's" << (isPal ? "" : " not a") << " palindrome";
return 0;
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
Verified answer
#include <iostream>
#include <cmath>
const int length = 6;
int main()
{
int numb;
std::cout << "Input number: ";
std::cin >> numb;
if (!(numb >= (int)pow(10, length - 1) && numb < (int)pow(10, length))) {
std::cout << "\nInput error!";
}
else {
bool isPal = true;
for (int i = 0; i < length / 2; i++) {
if (((numb % (int)pow(10, i + 1) - numb % (int)pow(10, i)) / (int)pow(10, i)) != (numb / (int)pow(10, length - 1 - i) - 10 * (numb / (int)pow(10, length - i)))) {
isPal = false;
}
}
std::cout << "\nIt's" << (isPal ? "" : " not a") << " palindrome";
}
return 0;
}