題目:
輸入乙個三位數的正整數,判斷它是否是水仙花數,所謂水仙花數是指這個數等於它每個位置上的數字的立方和
輸入:
輸入乙個三位數的正整數,首位不為0
輸出:如果是水仙花數,輸出「yes」,否則輸出「no」
這道題是學c++語言的中度難度,需要用到for迴圈,但是對於我這樣的高手小菜一碟,哈哈~~(我很自戀)
**:#include
using namespace std;
//ifstream cin(".in");
//ofstream cout(".out");
int main()
{int n,m;
cin>>n;
m=(n/100)*(n/100)*(n/100)+(n/10%10)*(n/10%10)*(n/10%10)+(n%10)*(n%10)*(n%10);
if(n==m)
cout<<"yes"<
請不要抄襲,還是自己手寫好!
希望大家喜歡我的文章!
水仙花數題解
水仙花數 3位數,其各位數字立方和為該數本身.include stdio.h void main int i,j,k,n 定義n的個位數為k,十位為j,百位為i printf narcissus numbers are for n 100 n 1000 n 使n從100 999迴圈 i n 100 ...
C 水仙花數
include include using namespace std void divide int,int int int void main int hun 0,ten 0,one 0 for int i 100 i 999 i divide i,hun,ten,one if i pow hu...
求水仙花 ghpython 水仙花數02
今天咱們繼續來看看老潘微博裡的乙個python小案例,求水仙花數,這個小案例在前兩天已經分享了,今天分享另一種方法,常言道只要思想不滑坡,方法總比困難多,而且今天的方法個人覺得更pythonic一點。水仙花數 四葉玫瑰數 五角星數 由於2位數的自冪數不存在,這裡直接從100遍歷到100000 for...