Board logo

標題: APCS_觀念題_10503_5 (練習) [打印本頁]

作者: 方浩葦    時間: 2024-9-7 00:54     標題: APCS_觀念題_10503_5 (練習)

本帖最後由 方浩葦 於 2024-9-7 14:14 編輯

函數 g 定義如下,若呼叫 g(500),指令 total = total + i 被執行的次數最接近下列何者?
  1. int g(int n)
  2. {
  3.     int total = 0;
  4.     if (n < 3)
  5.     {
  6.         return 0;
  7.     }
  8.     for (int i = 1; i <= n; i = i + 1)
  9.     {
  10.         total = total + i;
  11.     }
  12.     total = total + g(n / 2);
  13.     return total;
  14. }
複製代碼
(A) 500
(B) 1000
(C) 1500
(D) 2000

本帖隱藏的內容需要積分高於 1 才可瀏覽





歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/) Powered by Discuz! 7.2