C+ VISUAL STUDIO.. SHOW OUTPUT PLEASE
Write a program that computes the number of possible combinations to obtain a successful result of an arbitrary event. The formula for computing the possible combinations is given by:
C(n,k)= n! / [k! * (n - k)!]
where,
n = the number of events
k = number of success for that event
Use the recursive function factorial explained in the chapter to compute the possible combinations. The output should be displayed as follows:
C( n, k ) = the result,
where n and k are the numbers input by the user.
#include <iostream> using namespace std; long factorial(int n) { if (n == 0) return 1; else return n*factorial(n-1); } long combinations(int n, int k) { return factorial(n) / (factorial(k) * factorial(n-k)); } int main() { int n, k; cout << "Enter the number of events: "; cin >> n; cout << "Enter number of successes events: "; cin >> k; cout << "Total number of combinations = " << combinations(n, k) << endl; return 0; }
Get Answers For Free
Most questions answered within 1 hours.