Advertisement
Tusohian

Fibonacci in Prolog

Jun 20th, 2019
3,245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PL/I 0.32 KB | None | 0 0
  1. go:-
  2. write('Enter a no: '),read(N),nl,
  3. write('fibonacci series for: '),write(N),nl,write('elements are: '),
  4. A is 0,
  5. B is 1,
  6. write(A),write(' '),write(B),write(' '),
  7. fibonacci(N,A,B).
  8.  
  9. fibonacci(N,A,B):-
  10. (
  11. N<2, write('complete');
  12. C is A+B,
  13. write(C),write(' '),
  14. D is B,
  15. E is C,
  16. N1 is N-1,
  17. fibonacci(N1,D,E)
  18. ).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement