c++迭代器输出水仙花数
时间: 2023-11-20 12:30:50 浏览: 66
shuixianhuashu.rar_Visual_C++_
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int start, end;
cout << "请输入起始数:";
cin >> start;
cout << "请输入结束数:";
cin >> end;
for(int i = start; i <= end; i++)
{
int num = i;
int sum = 0;
int count = 0;
while(num > 0)
{
count++;
num /= 10;
}
num = i;
while(num > 0)
{
sum += pow(num % 10, count);
num /= 10;
}
if(sum == i)
cout << i << "是水仙花数" << endl;
}
return 0;
}
阅读全文