للفائدة
إن كانت النتائج صحيحة حمل الكود وإن لم تكن عدله بما يناسبك
كود:
#include<iostream>
using namespace std;
int Factorial(int N) // Function of (Number)!
{
int F;
F = 1;
for( ; N > 0 ; )
{
F = F * N ;
N = N - 1 ;
}
return F; }
float Formula(int n , int r,int NR) // Function of Formula
{
float Solve = 0;
Solve = Factorial(n) / ( Factorial(r) * Factorial(NR));
return Solve;
}
int main(){
//----------------------Define Variables
int n;
int r;
int n_r;
//----------------------real code
cout << "\n\n\t ==========================\n\t Define Variables \
\n\t -------------------------- \n\t Insert n : ";
cin >> n;
cout << "\t Insert r : ";
cin >> r;
n_r = n - r;
cout << "\n\n\t ==========================\n\t Variables Factory \
\n\t -------------------------- \n\t n! = " << Factorial(n)<< endl; // N!
cout << "\t r! = " << Factorial(r)<< endl;
cout << "\n\n\t ==========================\n\t Solve of Formula \
\n\t -------------------------- \n\t n!/(r! * (n-r)!) = " << Formula(n,r,n_r)<<endl<<endl<<endl;
system("pause");
return 0;
}