Advertisement
danzylrabago

Fibonacci

Mar 25th, 2020
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. using System;
  2. class Exercise1 {
  3.  
  4. public static string test(int range) {
  5. string ans = "";
  6. int first = 0, second = 1, fibonicci = 0;
  7.  
  8. for (int c = 0; c < range; c++) {
  9. if (c <= 1) {
  10. fibonicci = c;
  11. ans += (fibonicci.ToString()) + " ";
  12. } else {
  13. fibonicci = first + second;
  14. first = second;
  15. second = fibonicci;
  16. ans += (fibonicci.ToString()) + " ";
  17. }
  18.  
  19. }
  20. return ans;
  21. }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement