Saturday, September 28, 2019

Program 6 WAP to implement Factorial, Fibonacci of a given number.


Factorial -
Program-
factorial(0,1).
factorial(N,F):-
N>0,
N1 is N-1,
factorial(N1,F1),
F is N * F1.
Goal- To find Factorial of the number.
Output-


Fibonacci-
Program-
fib(0, 1) :- !.
fib(1, 1) :- !.
fib(N, F) :-
N > 1,
N1 is N-1,
N2 is N-2,
fib(N1, F1),
fib(N2, F2),
F is F1+F2
Goal- To find Fibonacci number.
Output-