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. }else if(n==2){
  7. return 2;
  8. }else{
  9.  
  10. return -6*rec(n-1)-9*rec(n-2);}
  11. }
  12.  
  13. int main(void) {
  14. int n = 4;
  15. printf("数列a%dの値は%d\n", n, rec(n));
  16. return 0;
  17. }
  18.  
  19.  
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
数列a4の値は108