Board logo

標題: APCS 觀念題 10603-18 [打印本頁]

作者: 陳育霖    時間: 2023-10-14 10:26     標題: APCS 觀念題 10603-18

下列程式執行完畢後所輸出值為何?
  1. int main()
  2. {
  3.     int x = 0, n = 5;
  4.     for (int i=1; i<=n; i=i+1)
  5.         for (int j=1; j<=n; j=j+1)
  6.        {
  7.             if ((i+j)==2)
  8.                 x = x + 2;
  9.             if ((i+j)==3)
  10.                 x = x + 3;
  11.             if ((i+j)==4)
  12.                 x = x + 4;
  13.        }
  14.     printf ("%d\n", x);
  15.     return 0;
  16. }
複製代碼
(A) 12
(B) 24
(C) 16
(D) 20




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