fork download
  1. #include <stdio.h>
  2. //フィボナッチ数列(再帰なし版)
  3. int main(void) {
  4. int n = 10;
  5. //ここを埋める
  6. int a,b=1,c=1;
  7. printf("%d, %d,",b,c);
  8. for(int i = 3; i <= n; i++){
  9. //ここも埋める
  10. a=b+c;
  11. c=b;
  12. b=a;
  13. printf(" %d,",a);
  14. }
  15. printf("\nフィボナッチ数列の第%d項は%d\n", n, a);
  16. return 0;
  17. }
  18.  
  19.  
Success #stdin #stdout 0s 5324KB
stdin
Standard input is empty
stdout
1, 1, 2, 3, 5, 8, 13, 21, 34, 55,
フィボナッチ数列の第10項は55