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