不使用palindrome,c++中寻找并输出11~999之间的数m,它满足m、m^2和m^3均为回文数
时间: 2024-05-20 12:17:35 浏览: 31
求11-999之间的回文数
4星 · 用户满意度95%
#include <stdio.h>
int is_palindrome(int n) {
int reversed = 0, original = n;
while (n > 0) {
reversed = reversed * 10 + n % 10;
n /= 10;
}
return original == reversed;
}
int main() {
int m;
for (m = 11; m <= 999; m++) {
int m_squared = m * m;
int m_cubed = m_squared * m;
if (is_palindrome(m) && is_palindrome(m_squared) && is_palindrome(m_cubed)) {
printf("%d\n", m);
}
}
return 0;
}
阅读全文