C++ Program Find ncR and nPr of any Number

Google Advertisements

Prev Tutorial Next Tutorial

C++ Program to Find ncR and nPr of any Number

Basically in NCR, AB is a single combination. But in NPR, AB and BA are two different permutations of a combination of A and B. The difference is quite clear and is easy for us to note that permutations are always equal to of greater in most cases than the combinations of elements. Also note that any number raised to the power of zero is one. This is a situation encountered during calculation of NCR and NPR.

To understand below example, you have must knowledge of following C++ programming topics; For Loop in C++, Function C++ and Function Arguments in C++

Find ncR and nPr of any Number in C++

#include<iostream.h>
#include<conio.h>

long int fact(int);   //function declaration
void main()
{
	clrscr();
	int n, r;
	long int ncr, npr;
	cout<<"Enter Any Value for n: ";
	cin>>n;
	cout<<"Enter Any Value for r: ";
	cin>>r;
	npr=fact(n)/fact(n-r);    // function calling
	ncr=npr/fact(r);          //function calling
	cout<<"NPR value = "<<npr<<"\n";
	cout<<"NCR value = "<<ncr<<"\n";
	getch();
}
long int fact(int x)          //defining the function
{
	int i, f=1;
	for(i=2; i<=x; i++)
	{
		f=f*i;
	}
	return f;
}

Output

Enter Any Value for n: 3
Enter Any Value for r: 2
NPR Value: 6
NCR Vlaue: 3
c++ program to find factrors on any number
Prev Tutorial Next Tutorial

Google Advertisements

We have more than 5 Groups which have 500000+ Members and some Pages have more than 100000+ members. If you want to post your article on our website/FB Group/FB Page please contact on hitesh.xc@gmail.com or 8076671483

Buy This Ad Space @$50 per Month, Ad Size 600X200 Contact on: hitesh.xc@gmail.com or 8076671483

Path variable is set for providing path for all Java tools like java, javac, javap, javah, jar, appletviewer which are used in java programming. All these tools are available in bin folders so we set path upto bin folders.

Classpath variable is set for providing a path for predefined Java classes which is used in our application. All classes are available in lib/rt.jar so we set classpath upto lib/rt.jar.

Cloud computing is the on demand availability of computer system resources, especially data storage and computing power, without direct active management by the user.

College Projects Related to Java, AWT, C Projects for College, C++ Projects for College, Android Projects.

Download Projects

Adsense Advertisements


Buy This ads Space 8076671483

Buy This Ad Space @$120 per Month, Ad Size 300X600 Contact on: hitesh.xc@gmail.com or 8076671483