酷代码 AI
菜单
服务商

C++ 编程:计算并输出 1 - 1000 内所有水仙花数

以下是使用 C++语言解决此问题的代码: ```cpp #include <iostream> int main() { for (int num = 100; num <= 999; num++) { int hundreds = num / 100; int tens = (num % 100) / 10; int units = num % 10; int cubeSum = hundreds * hundreds * hundreds + tens * tens * tens + units * units * units; if (cubeSum == num) { std::cout << num << " "; } } return 0; } ``` ######[AI写代码神器 | 148点数解答 | 2024-10-14 20:46:56]

相关提问
本站限时免费提问中
实用工具查看更多
Linux在线手册 [开发类]
Jquery在线手册 [开发类]
今日油价 [生活类]
图片互转base64 [开发类]
时间转换器 [开发类]