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. }
  7. else {
  8. return -2*rec(n-1)+4;
  9. }
  10. }
  11. int main(void) {
  12. int n;
  13. scanf("%d",&n);
  14. printf("数列a%dの値は%d\n", n, rec(n));
  15. return 0;
  16. }
Success #stdin #stdout 0s 5288KB
stdin
1
stdout
数列a1の値は0