narcissus number.cpp
来自「实现了水仙花数问题。界面为dos界面」· C++ 代码 · 共 44 行
CPP
44 行
//******************************* Narcissus number *******************************************************
//所谓“水仙花数”是指一个三位数,其各位数字立方之和等于该数本身
//********************************************************************************************************
//求出所有的水仙花数
#include"iostream"
#include"iomanip"
using namespace std;
int main()
{
int a,b,c;
int n;
int m=0;
for(n=100;n<=999;n++) //判断n是否为“水仙花数”
{
a=n%10;
b=(n%100-a)/10;
c=(n-n%100)/100;
if(n==a*a*a+b*b*b+c*c*c)
{
cout<<setw(5)<<n;
m=m+1;
if(m%10==0)
cout<<endl;
}
else
continue;
}
cout<<endl;
cout<<"The total number of Narcissus number is:"<<m<<endl;
return 0;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?