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