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