fork 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. int main(void) {
  18. int n=4;
  19. printf("a%dの値は%d\n",n,rec(n));
  20. printf("このときrecの呼び出し回数は%d\n",c);
  21. return 0;
  22. }
  23.  
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
a4の値は108
このときrecの呼び出し回数は5