fork(1) download
  1. #include <stdio.h>
  2. //課題3
  3. int rec(int n){
  4. //rec内を完成させてください
  5. if(n==0){
  6. return 3;
  7. }
  8. else if(n==1){
  9. return 0;
  10. }
  11. else if(n==2){
  12. return 2;
  13. }
  14. else{
  15. return rec(n-2)+rec(n-3);
  16. }
  17. }
  18.  
  19. int main(void) {
  20. int n = 50;
  21. for(int i = 0; i <= n; i++){
  22. printf("第%d項は%d\n, ", i,rec(i));
  23. }
  24.  
  25. return 0;
  26. }
  27.  
  28.  
Success #stdin #stdout 0.01s 5300KB
stdin
Standard input is empty
stdout
第0項は3
, 第1項は0
, 第2項は2
, 第3項は3
, 第4項は2
, 第5項は5
, 第6項は5
, 第7項は7
, 第8項は10
, 第9項は12
, 第10項は17
, 第11項は22
, 第12項は29
, 第13項は39
, 第14項は51
, 第15項は68
, 第16項は90
, 第17項は119
, 第18項は158
, 第19項は209
, 第20項は277
, 第21項は367
, 第22項は486
, 第23項は644
, 第24項は853
, 第25項は1130
, 第26項は1497
, 第27項は1983
, 第28項は2627
, 第29項は3480
, 第30項は4610
, 第31項は6107
, 第32項は8090
, 第33項は10717
, 第34項は14197
, 第35項は18807
, 第36項は24914
, 第37項は33004
, 第38項は43721
, 第39項は57918
, 第40項は76725
, 第41項は101639
, 第42項は134643
, 第43項は178364
, 第44項は236282
, 第45項は313007
, 第46項は414646
, 第47項は549289
, 第48項は727653
, 第49項は963935
, 第50項は1276942
,