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("%d",c);
  13. printf("数列a%dの値は%d\n", n, a);
  14. return 0;
  15. }
  16.  
  17.  
Success #stdin #stdout 0.01s 5360KB
stdin
Standard input is empty
stdout
-21数列a4の値は108