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