Write a Prolog program that computes binomial coefficient
program.pl:
bc(N, 0, 1) :- N >= 0.% base case 1 binomial_coefficient is 1
for (N,0)
bc(N, N, 1) :- N > 0.% base case 2 binomial_coefficient is 1 for
(N,N)
bc(N,K,R):-
factorial(N,F1),% finds n!
factorial(K,F2),% finds k!
factorial(N-K,F3),% finds (n-k)!
R is F1/(F2*F3).
% we know that binomial coefficient formula binomial_coefficient (n
k) = n!/(k!(n-k)!
% program to find factorial of n
factorial(0,1).
factorial(N,F) :-
N>0,
N1 is N-1,
factorial(N1,F1),
F is N * F1.
Output:
C++: Write a program that computes and displays a full binomial expansion, such as (x+y)^n where only n is asked for by the user.
1. Write a Prolog program that returns the length of a list of numbers. For example: size([1, 2, 3, 4], len). then return len=4. 2. Write a Prolog program that reverses the given list. For example: reverse([a, b, c, d], X). then return X=[d, c, b, a].
Write a Prolog program to find the maximum, minimum, and range of values in a list of numbers. Please also provide the program with output.
1. Write a C++ program to compute the Binomial Coefficient to construct a 2D array using two input parameters: n and k Then once the table is constructed Display the entire table according to rows and columns. Give user a choice of computing the Binomial coefficient at various values of n and k using this table,i.e. prompt the user to enter a value of i and j (i <= n and j <= k), code first test if the input...
Write a program in prolog to reverse the elements of a list. Don't call the following library functions that already exist. reverse_list([], []). reverse_list([Head | Tail], Out) :- reverse_list(Tail, TailReversed), append(TailReversed, [Head], Out).
for future viewers please dont use this for spring 2020 Write a Prolog program to split a list into two lists of positive and negative numbers. For example: ?- split([20,-10,30,22,45,0,-15,0,12], L1, L2). L1 = [20,30,22,45,12] L2 = [-10,-15]
For each of the following English statements write a prolog program. % Facts & Rules (1) jane is a woman. (2) john is a man. (3) john is healthy. (4) jane is healthy. (5) john is wealthy. (6) anyone is a traveler if he is healthy and wealthy. (7) anyone can travel if he is a traveler. % Goals (queries). (8) Who can travel? (9) Who is healthy and wealthy?
Write a program that reads a sequence of integers into an array and that computes the alternating sum of all elements in the array. For example, if the program is executed with the input data: 2 1 4 9 16 9 7 4 9 11 Then it computes 2 - 1 + 4 - 9 + 16 - 9 + 7 - 4 + 9 – 11 = 4 Use a scanner object to gather the inputs from the user....
///Program needs to write in prolog/// 6. A binary tree is either empty or it is composed of a root element and two successors, which are binary trees themselves. In Prolog we represent the empty tree by the atom 'nil' and the non-empty tree by the term t(X,L,R), where X denotes the root node and L and R denote the left and right subtree, respectively. The following Prolog term represents the given binary tree below. T1 = t(a,t(b,t(d,nil,nil),t(e,nil,nil)),t(c,nil,t(f,t(g,nil, nil),nil))) d...
In C++, Write a program that it prompts to user for two integers, computes the quotient of two integers, and then displays the result. You need to do the following things in this assignment: + The main function prompts for user input and reads the two integers that the user entered. + Write a quotient function that computes the quotient of two integers and return the results. (hint: avoid integer division and divide by zero)