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 n = 4;
  6. int a, b = 2, c = 1;
  7. for(int i = 3; i <= n; i++){
  8. a = -6*b -9*c;
  9. c = b;
  10. b = a;
  11. }
  12. printf("数列a%dの値は%d\n", n, a);
  13. return 0;
  14. }
  15.  
  16.  
Success #stdin #stdout 0s 5288KB
stdin
Standard input is empty
stdout
数列a4の値は108