请用c语言设计一个程序,其根据标准输入获得的一个自然数,打印所有大于10且小于该自然数的超完全数字不变数的倒序排列
时间: 2024-06-06 17:08:13 浏览: 102
#include <stdio.h>
int isPerfect(int n) {
int sum = 0;
for (int i = 1; i < n; i++) {
if (n % i == 0) {
sum += i;
}
}
return sum == n;
}
int isPalindrome(int n) {
int temp = n, reverse = 0;
while (temp != 0) {
reverse = reverse * 10 + temp % 10;
temp /= 10;
}
return n == reverse;
}
int main() {
int n;
scanf("%d", &n);
for (int i = 11; i < n; i++) {
if (isPerfect(i) && isPalindrome(i)) {
int temp = i, reverse = 0;
while (temp != 0) {
reverse = reverse * 10 + temp % 10;
temp /= 10;
}
printf("%d ", reverse);
}
}
return 0;
}
阅读全文