Premutations

The number of permutations of a set of n items taken r at a time is given by the following formula
n!/r!(n-r)!

Where N! is the factorial of n. if there are 12 people in your class and you want to divide the class into teams of 3 members, you can compute the number of different teams that can be arranged using this formula. Write a C++ program that detemines the number of potential team assignments. you will need to use the double type for this computation. Be sure to use proper formating and appropriate comments in your code. the outputs should be labled clearly and formated neatly.




#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;

int main()
{
const double PI = 3.14;
double n = 12.0;
double r = 3.0;
double nmr = 15.0;
double nFact = exp(-n) * pow(n, n) * sqrt(2 * PI * n);
double rFact = exp(-r) * pow(r, r) * sqrt(2 * PI * r);
double nmrFact = exp(-nmr) * pow(nmr, nmr) *sqrt(2 * PI * nmr);
//using sterlings formula
// cout <<setprecision(2)
// <<n<<"! = "
// <<exp(-n) * pow(n, n) * sqrt(2 * PI * n)<<endl;

cout << "The number of teams that can be arranged ="
<<nFact/(rFact*nmrFact)<<endl;


system("PAUSE");
return 0;
}
1
2
3
double n = 12.0;
double r = 3.0;
double nmr = 15.0; //n+r = 12+3 

The formula n!/[r!(n-r)!]


what a waste of an exercise.
Last edited on
Topic archived. No new replies allowed.