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