[問題] 用function解阿姆斯壯數

看板C_and_CPP作者 (★)時間12年前 (2011/10/02 11:26), 編輯推噓1(106)
留言7則, 4人參與, 最新討論串1/1
題目:Write a function that determines whether a number is an Armstrong number. Use this function in a program that prints all Armstrong numbers between and including 10 and a positive integer (in the range from 10 to 10000000) input by the user. 程式碼:http://pastie.org/2624919 結果大概是這樣 ┌───────────────────────────────┐ │Enter an integer between and including 10 and 10000000: 20000 │ │ │ │Armstrong numbers between and including 10 and 20000: │ │ │ │ 153 │ │ 370 │ │ 371 │ │ 407 │ │ 1634 │ │ 8208 │ │ 9474 │ │請按任意鍵繼續 . . . │ └───────────────────────────────┘ 請問function最後的return寫在迴圈裡那回傳到main的時候會有很多個值嗎? 如果要cout每個值那main裡面還要再寫一個迴圈嗎? 我試了很多次還是沒有辦法輸出答案 剛學C++,有很多寫不好的地方請多多指正 :) -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 218.167.191.190 ※ 編輯: hedwing 來自: 218.167.191.190 (10/02 11:27)

10/02 11:39, , 1F
把結果放到陣列裡面最後再印不就好了
10/02 11:39, 1F

10/02 13:40, , 2F
main中的number4=armstrong(input)先修改?
10/02 13:40, 2F

10/02 13:49, , 3F
另外需在增加判斷是否輸出非Armstrong數值
10/02 13:49, 3F

10/02 14:24, , 4F
你沒有搞懂題目的需求喔...題目要求該函式檢查某數是否為
10/02 14:24, 4F

10/02 14:24, , 5F
Armstrong number 而不是傳一些數字回來
10/02 14:24, 5F

10/02 14:25, , 6F
主程式則是利用這個函式來輸出題目要的列表
10/02 14:25, 6F

10/02 17:38, , 7F
先建表,然後bsearch
10/02 17:38, 7F
文章代碼(AID): #1EXzdfbp (C_and_CPP)