题解 | #输出水仙花数#
输出水仙花数
http://www.nowcoder.com/practice/dabaf13009ef4d0cbf22302fd6a530a6
#include using namespace std;
int main() {
int num = 99;
do
{
num++;
int a, b, c = 0;
a = num / 100;
b = (num % 100) / 10;
c = (num % 10);
int num1 = a * a * a + b * b * b + c * c * c;
if (num1 == num)
{
cout << num1 << endl;
}
} while (num<999);//do while循环时需要注意while满足是的条件,
//如果是先输出,后加一,则需要‘小于1000,如果是先加一 后输出,则是小于999;
//do循环先分解出三个数,然后每次加一,中间嵌套一个if语句,满足进行输出,不满足继续;
return 0; }