水仙花数为什么无法得出?
!
Can you help me?
Thank you very much!
#include <iostream>
int cube(int x) { return x * x * x; }
int main()
{
int n = 100;
int a[3];
do
{
int x = n;
int i = 0;
while (x)
{
a[i++] = x % 10;
x /= 10;
}
if (cube(a[0]) + cube(a[1]) + cube(a[2]) == n)
std::cout << n << '\n';
} while (++n < 1000);
return 0;
}