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