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