#include <iostream>
#include <conio.h>
using namespace std;
int fict(int n)
{
int i, sum=1;
for(i=1; i<=n; i++)
{
sum = sum*i;
}
return sum;
}
main()
{
char status, find;
int n, r, ans;
while(status != 'n')
{
cout << "\n1: nCr\n2: nPr\n";
find = getch();
cout << "Enter value of n: ";
cin >> n;
cout << "Enter value of r: ";
cin >> r;
if(find == '1')
{
ans = fict(n) /( fict(r) * fict(n-r));
cout << "\nAnswer of "<<n<<"C"<<r<<" is: "<<ans<<endl;
}
else if(find == '2')
{
ans = fict(n) / fict(n-r);
cout << "\nAnswer of "<<n<<"P"<<r<<" is: "<<ans<<endl;
}
else
{
cout << "Enter valid input."<<endl;
}
cout << "You like to calculate again? n/y.";
status = getch();
}
system("pause");
}
#include <conio.h>
using namespace std;
int fict(int n)
{
int i, sum=1;
for(i=1; i<=n; i++)
{
sum = sum*i;
}
return sum;
}
main()
{
char status, find;
int n, r, ans;
while(status != 'n')
{
cout << "\n1: nCr\n2: nPr\n";
find = getch();
cout << "Enter value of n: ";
cin >> n;
cout << "Enter value of r: ";
cin >> r;
if(find == '1')
{
ans = fict(n) /( fict(r) * fict(n-r));
cout << "\nAnswer of "<<n<<"C"<<r<<" is: "<<ans<<endl;
}
else if(find == '2')
{
ans = fict(n) / fict(n-r);
cout << "\nAnswer of "<<n<<"P"<<r<<" is: "<<ans<<endl;
}
else
{
cout << "Enter valid input."<<endl;
}
cout << "You like to calculate again? n/y.";
status = getch();
}
system("pause");
}