fork(1) download
  1. #include <stdio.h>
  2.  
  3. int c=0;
  4.  
  5. int rec(int n){
  6. c++;
  7. if(n==1){
  8. return 1;
  9. }
  10. else if(n==2){
  11. return 2;
  12. }
  13. else{
  14. return -6*rec(n-1)-9*rec(n-2);
  15. }
  16. }
  17.  
  18.  
  19. int main(void) {
  20. int n;
  21. scanf("%d",&n);
  22.  
  23. int result=rec(n);
  24. printf("数列a%dの値は%d\n",n,result);
  25. printf("この時recの呼び出し回数は%d\n",c);
  26. return 0;
  27. }
  28.  
Success #stdin #stdout 0s 5308KB
stdin
5
stdout
数列a5の値は-459
この時recの呼び出し回数は9