Advertisement
danzylrabago

RecursionFibonacci

Mar 26th, 2020
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.38 KB | None | 0 0
  1. class Exercise1
  2. {
  3.  
  4. public static int fibonacci(int n)
  5. {
  6. if((n==1)||(n==0))
  7. {
  8. return(n);
  9. }
  10. else
  11. {
  12. return(fibonacci(n-1)+fibonacci(n-2));
  13. }
  14. }
  15.  
  16. public static string test(int n)
  17. {
  18. int i=0;
  19. string ans="";
  20. while(i<n)
  21. {
  22. ans =ans + (fibonacci(i)).ToString() +" ";
  23. i=i+1;
  24. }
  25.  
  26. return ans;
  27. }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement