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