応用情報 午前ラボ

学習の画面へ

階乗の再帰的定義

出典: 平成29年度 秋期 応用情報技術者試験 午前 問7 (IPA)

fact (n) は,非負の整数 n に対して n の階乗を返す。fact (n) の再帰的な定義はどれか。

  1. ア if n=0 then return 0 else return n×fact(n-1)
  2. イ if n=0 then return 0 else return n×fact(n+1)
  3. ウ if n=0 then return 1 else return n×fact(n-1)
  4. エ if n=0 then return 1 else return n×fact(n+1)
正解と解説を見る

正解: ウ

ポイント

「アルゴリズムとプログラミング」をこのサイトで解く (記録・間違えた問題の解き直し・AI教師への質問)