fork download
  1. #include <stdio.h>
  2. //フィボナッチ数列
  3. int rec(int n){
  4. int a1=1;
  5. int a2=1;
  6. int a3;
  7. for(int i=3;i<=n;i++){
  8. a3=a2+a1;
  9. a1=a2;
  10. a2=a3;
  11. }
  12. return a3;
  13. }
  14.  
  15. int main(void) {
  16. int n = 10;
  17. printf("フィボナッチ数列の第%d項は%d\n", n, rec(n));
  18. return 0;
  19. }
  20.  
  21.  
Success #stdin #stdout 0s 5276KB
stdin
Standard input is empty
stdout
フィボナッチ数列の第10項は55