fork download
  1. #include <stdio.h>
  2. //a{n+1} = -2a{n} + 4, a{0}=2(再帰なし版)
  3. int main(void) {
  4. int n;
  5. int an=2;
  6. scanf("%d",&n);
  7. for(int i=0;i<n;i++){
  8. an=-2*an+4;
  9. }
  10. printf("数列a%dの値は%d\n", n, an);
  11.  
  12. return 0;
  13. }
  14.  
  15.  
Success #stdin #stdout 0s 5268KB
stdin
3
stdout
数列a3の値は-4