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 = 1;
  6. int a, b = 2, c = 1;
  7. if(n==1){
  8. a=1;
  9. }
  10. else if(n==2){
  11. a=2;
  12. }
  13. else{
  14. for(int i = 3; i <= n; i++){
  15. a = -6*b -9*c;
  16. c = b;
  17. b = a;
  18. }
  19. }
  20. printf("数列a%dの値は%d\n", n, a);
  21. return 0;
  22. }
  23.  
  24.  
Success #stdin #stdout 0.01s 5284KB
stdin
Standard input is empty
stdout
数列a1の値は1