User:Shyal-b/Sandbox/permutations

From Wikipedia, the free encyclopedia

#include <iostream>
#include <vector>

using namespace std;
double factorial(int a) { double r = a; if (a > 0) { while (--a) { r *= a; } } else { r = 1; } return r; }
int permutations(int n, int r) { return((int)(factorial(n)/factorial(n-r))); }
int main() { int n, r;
cout << "Enter any n and r to compute its permutations" << endl;
cout << "n : "; cin >> n; cout << "r : "; cin >> r;
long p = permutations(n, r);
cout << "permutations : " << p << endl;
return 0; }