Write a program in PROLOG to implement generate_fib(N,T) where T represents the Nth term of the fibonacci series.

4. Write a program in PROLOG to implement generate_fib(N,T) where T represents the Nth term of the fibonacci series.

% Write a program in PROLOG to implement generate_fib(N,T) where T 
  represents the Nth term of the fibonacci series.

%  below generate_fib function is not predefined you can use any name as function

generate_fib(0,1).
generate_fib(1,1).
generate_fib(N,T):- N1 is N-1, 
generate_fib(N1,T1),
N2 is N-2, 
generate_fib(N2,T2), 
T is T1+T2.

% Output


No comments:

Post a Comment

Featured post

Amazon Interview Process

On July 5, 1994, Jeff Bezos started the world's most "customer-centric" firm out of his garage in Bellevue, Washington. The A...