返回列表 發帖

[隨堂測驗] 遞迴函式 (二) - 計算總和

本帖最後由 tonyh 於 2019-1-25 09:44 編輯



請同學們用函式遞迴法接著完成第15~18行之程式碼.
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int total(int);
  5. int main()
  6. {
  7.     cout<<"1+2+3+...+5="<<total(5)<<endl;
  8.     cout<<"1+2+3+...+101="<<total(101)<<endl;
  9.     cout<<"1+2+3+...+257="<<total(257)<<endl;
  10.     system("pause");   
  11.     return 0;
  12. }
  13. int total(int x)
  14. {
  15.    
  16.    


  17. }
複製代碼

此帖僅作者可見

TOP

此帖僅作者可見
ABCDEFGHIJKLMNOPQRSTUVWXYZ

TOP

此帖僅作者可見

TOP

此帖僅作者可見

TOP

返回列表