fork download
  1. #include <stdio.h>
  2. //a{n} = -6a{n-1} -9a{n-2}, a{1}=1, a{2}=2(再帰あり版)
  3. int rec(int n){
  4. if(n==1){
  5. return 1;
  6. }
  7. else if(n==2){
  8. return 2;
  9. }
  10. else{
  11. return -6*rec(n-1)-9*rec(n-2);
  12. }
  13. }
  14.  
  15. int main(void) {
  16. int n = 4;
  17. printf("数列a%dの値は%d\n", n, rec(n));
  18. return 0;
  19. }
  20.  
  21.  
Success #stdin #stdout 0s 5288KB
stdin
Standard input is empty
stdout
数列a4の値は108