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