C语言求在两个数之前的水仙花数的个数
时间: 2024-02-04 11:14:04 浏览: 70
C语言实现求水仙花数
以下是使用C语言编写的求解在两个数之间的仙花数的个数的程序:
```c#include <stdio.h>
#include <math.h>
int main() {
int start, end, num, originalNum, remainder, = 0, result =0, count = 0;
printf("请输入两个数字,以空格分隔:");
scanf("%d %d", &start, &end);
for (num = start; num <= end; num++) {
originalNum = num;
while (originalNum != 0) {
originalNum /= 10;
++n;
}
originalNum = num;
while (originalNum != 0) {
remainder = originalNum % 10;
result += pow(remainder, n);
originalNum /= 10;
}
if (result == num) {
count++;
printf("%d ", num);
}
n = 0;
result = 0;
}
printf("\n在 %d 和 %d 之间的水仙花数的个数为:%d\n", start, end, count);
return 0;
}
```
程序会要求用户输入两个数字,然后输出在这两个数字之间的所有水仙花数,并统计其个数。
阅读全文