【发布时间】:2018-08-13 15:07:48
【问题描述】:
我尝试将用户输入的位数的所有自恋数字打印出来。
例如对于输入3,程序应打印:153, 370, 371, 407。现在由于某种原因,它没有打印数字,而是什么都不打印,程序就卡住了。
#include <stdio.h>
#include <math.h>
int main() {
int digit, a, c = 0;
unsigned long long int count, b, sum;
printf("Enter digits to check narcisistic: ");
scanf("%d", &digit);
count = pow(10, digit - 1);
if (digit > 2) {
while (count < pow(10, digit)) {
b = count;
sum = 0;
while (count >= 1) {
a = b % 10;
b /= 10;
sum += pow(a, digit);
}
if (sum == count) {
printf("\n Narcissistic found:\t%llu", count);
c++;
}
count++;
}
if (c == 0)
printf("No Narcissistic number for this digit.");
}
return 0;
}
这段代码有什么问题?
【问题讨论】:
标签: c while-loop nested-loops