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