Question

C+ VISUAL STUDIO.. SHOW OUTPUT PLEASE Write a program that computes the number of possible combinations...

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.

Homework Answers

Answer #1
#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;
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Im using visual studio to write a c++ program has a function that will output the...
Im using visual studio to write a c++ program has a function that will output the number if ways a person can climb stairs using only 1 or two steps and and function that when given a number outputs the corresponding fibonacci number. I want to call the functions in main;
Im using visual studio to write a c++ program has a function that will output the...
Im using visual studio to write a c++ program has a function that will output the number if ways a person can climb stairs using only 1 or two steps and and function that when given a number outputs the corresponding fibonacci number. I want to call the functions in main. #include <iostream> using namespace std; int FiboNum(int fiboNum); int Stairs(int nStairs); int main() {    int fiboNum;    int nStairs;    cout << "Enter a number : " <<...
IN C++ PLEASE. Write a program where the user enters a number and you output an...
IN C++ PLEASE. Write a program where the user enters a number and you output an unfilled square of stars. (DO NOT PROMPT THE USER, just take in a number, The only console output should be the squares). For example the program would start with console input, The user would enters 3, you would output (note 3 is the lowest number your program will be tested with) *** * * *** or, The user enters 5, you would output *****...
Please write C++ program. Fibonacci numbers have the property that each consecutive number is a sum...
Please write C++ program. Fibonacci numbers have the property that each consecutive number is a sum of two preceding: 0, 1, 1, 2, 3, 5, 8, 13, 21 ..... Your program should ask user for the integer, and output the result, which shows Fibonacci number at that position. For example if user enters '5', program should output '3' (fifth position in the series). Your program should use recursive function to compute and return back to the main the Fibonacci number....
Problem: Our Armstrong number Please write code for C language So far we have worked on...
Problem: Our Armstrong number Please write code for C language So far we have worked on obtaining individual digits from 4 digits or 5 digit numbers. Then added them to find the sum of digits in various examples and assignments. However, the process of extracting individual digits is actually can be solved using a loop as you were doing a repetitive task by using mod operation and division operation. Now, we know how loops work and we can remove the...
You will write a program that loops until the user selects 0 to exit. In the...
You will write a program that loops until the user selects 0 to exit. In the loop the user interactively selects a menu choice to compress or decompress a file. There are three menu options: Option 0: allows the user to exit the program. Option 1: allows the user to compress the specified input file and store the result in an output file. Option 2: allows the user to decompress the specified input file and store the result in an...
Please read the article and answear about questions. Determining the Value of the Business After you...
Please read the article and answear about questions. Determining the Value of the Business After you have completed a thorough and exacting investigation, you need to analyze all the infor- mation you have gathered. This is the time to consult with your business, financial, and legal advis- ers to arrive at an estimate of the value of the business. Outside advisers are impartial and are more likely to see the bad things about the business than are you. You should...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT