fork download
  1. #include <stdio.h>
  2. int fib(int n){
  3. if (n==0){
  4. return 0;
  5. }
  6. if (n==1){
  7. return 1;
  8. }
  9. else return fib(n-1)+fib(n-2);
  10. }
  11.  
  12. int main(void) {
  13. int n;
  14. scanf("%d",&n);
  15. if (n<0){
  16. return 1;
  17. }
  18. int result = fib(n);
  19. printf("第%d項の値は%d",n,result);
  20. // your code goes here
  21. return 0;
  22. }
  23.  
Success #stdin #stdout 0.01s 5324KB
stdin
7
stdout
第7項の値は13