Technology

# How to Calculate the Value of nCr

Mixture is a mathematical idea. It refers back to the association of a number of objects the place their order is irrelevant. A fundamental method describes the variety of legitimate combos.

On this article, you may discover ways to calculate the worth of nCr utilizing Python, C++, JavaScript, C, and Java. Every instance additionally accommodates pattern output for a number of completely different values.

## Methods to Calculate nCr

Use the next mixture method to calculate the worth of nCr:

``nCr = n! / (r! * (n-r)!)``

The place:

``n = Whole quantityC = Mixturer = Association! = Factorial``

## Drawback Assertion

You are given the values of n and r. It’s good to calculate the worth of nCr.

Instance 1: Let n = 10 and r = 5.

Subsequently, nCr = 10! / (5! * (10-5)!) = 10! / (5! * 5!) = 252.

Thus, the output is 252.

Instance 2: Let n = 8 and r = 0.

Subsequently, nCr = 8! / (0! * (8-0)!) = 8! / (0! * 8!) = 1.

Thus, the output is 1.

## C++ Program to Calculate the Worth of nCr

Beneath is the C++ program to calculate the worth of nCr:

``// C++ program to calculate the worth of nCr#embody <iostream>utilizing namespace std;// Operate to calculate the factorial of a quantityint factorial(int num){if (num<=1){return 1;}return num*factorial(num-1);}// Operate to calculate the worth of nCrint calculate_nCr(int n, int r){return factorial(n) / (factorial(r) * factorial(n - r));}int principal(){int n1 = 10;int r1 = 5;cout << "n: " << n1 << ", r: " << r1 << endl;cout << "Worth of nCr: " << calculate_nCr(n1, r1) << endl;int n2 = 3;int r2 = 2;cout << "n: " << n2 << ", r: " << r2 << endl;cout << "Worth of nCr: " << calculate_nCr(n2, r2) << endl;int n3 = 1;int r3 = 1;cout << "n: " << n3 << ", r: " << r3 << endl;cout << "Worth of nCr: " << calculate_nCr(n3, r3) << endl;int n4 = 8;int r4 = 0;cout << "n: " << n4 << ", r: " << r4 << endl;cout << "Worth of nCr: " << calculate_nCr(n4, r4) << endl;int n5 = 4;int r5 = 4;cout << "n: " << n5 << ", r: " << r5 << endl;cout << "Worth of nCr: " << calculate_nCr(n5, r5) << endl;return 0;}``

Output:

``n: 10, r: 5Worth of nCr: 252n: 3, r: 2Worth of nCr: 3n: 1, r: 1Worth of nCr: 1n: 8, r: 0Worth of nCr: 1n: 4, r: 4Worth of nCr: 1``

## Python Program to Calculate the Worth of nCr

Subsequent, is the Python code to calculate the Worth of nCr:

``# Python program to calculate the worth of nCr# Operate to calculate the factorial of a quantitydef factorial(num):if num<=1:return 1return num*factorial(num-1)# Operate to calculate the worth of nCrdef calculate_nCr(n, r):return factorial(n) // (factorial(r) * factorial(n - r))n1 = 10r1 = 5print("n:", n1, ",r:", r1)print("Worth of nCr:", calculate_nCr(n1, r1))n2 = 3r2 = 2print("n:", n2, ",r:", r2)print("Worth of nCr:", calculate_nCr(n2, r2))n3 = 1r3 = 1print("n:", n3, ",r:", r3)print("Worth of nCr:", calculate_nCr(n3, r3))n4 = 8r4 = 0print("n:", n4, ",r:", r4)print("Worth of nCr:", calculate_nCr(n4, r4))n5 = 4r5 = 4print("n:", n5, ",r:", r5)print("Worth of nCr:", calculate_nCr(n5, r5))``

Output:

``n: 10, r: 5Worth of nCr: 252n: 3, r: 2Worth of nCr: 3n: 1, r: 1Worth of nCr: 1n: 8, r: 0Worth of nCr: 1n: 4, r: 4Worth of nCr: 1``

## JavaScript Program to Calculate the Worth of nCr

Here is how one can calculate the worth of nCr utilizing JavaScript:

``// JavaScript program to calculate the worth of nCr// Operate to calculate the factorial of a quantityoperate factorial(num) {if (num<=1) {return 1;}return num*factorial(num-1);}// Operate to calculate the worth of nCroperate calculate_nCr(n, r) {return factorial(n) / (factorial(r) * factorial(n - r));}var n1 = 10;var r1 = 5;doc.write("n: " + n1 + ", r:" + r1 + "<br>");doc.write("Worth of nCr: " + calculate_nCr(n1, r1) + "<br>");var n2 = 3;var r2 = 2;doc.write("n: " + n2 + ", r:" + r2 + "<br>");doc.write("Worth of nCr: " + calculate_nCr(n2, r2) + "<br>");var n3 = 1;var r3 = 1;doc.write("n: " + n3 + ", r:" + r3 + "<br>");doc.write("Worth of nCr: " + calculate_nCr(n3, r3) + "<br>");var n4 = 8;var r4 = 0;doc.write("n: " + n4 + ", r:" + r4 + "<br>");doc.write("Worth of nCr: " + calculate_nCr(n4, r4) + "<br>");var n5 = 4;var r5 = 4;doc.write("n: " + n5 + ", r:" + r5 + "<br>");doc.write("Worth of nCr: " + calculate_nCr(n5, r5) + "<br>");``

Output:

``n: 10, r: 5Worth of nCr: 252n: 3, r: 2Worth of nCr: 3n: 1, r: 1Worth of nCr: 1n: 8, r: 0Worth of nCr: 1n: 4, r: 4Worth of nCr: 1``

## C Program to Calculate the Worth of nCr

Beneath is the C program to calculate the worth of nCr:

``// C program to calculate the worth of nCr#embody <stdio.h>// Operate to calculate the factorial of a quantityint factorial(int num){if (num<=1){return 1;}return num*factorial(num-1);}// Operate to calculate the worth of nCrint calculate_nCr(int n, int r){return factorial(n) / (factorial(r) * factorial(n - r));}int principal(){int n1 = 10;int r1 = 5;printf("n: %d, r: %d ⁠n", n1, r1);printf("Worth of nCr: %d ⁠n", calculate_nCr(n1, r1));int n2 = 3;int r2 = 2;printf("n: %d, r: %d ⁠n", n2, r2);printf("Worth of nCr: %d ⁠n", calculate_nCr(n2, r2));int n3 = 1;int r3 = 1;printf("n: %d, r: %d ⁠n", n3, r3);printf("Worth of nCr: %d ⁠n", calculate_nCr(n3, r3));int n4 = 8;int r4 = 0;printf("n: %d, r: %d ⁠n", n4, r4);printf("Worth of nCr: %d ⁠n", calculate_nCr(n4, r4));int n5 = 4;int r5 = 4;printf("n: %d, r: %d ⁠n", n5, r5);printf("Worth of nCr: %d ⁠n", calculate_nCr(n5, r5));return 0;}``

Output:

``n: 10, r: 5Worth of nCr: 252n: 3, r: 2Worth of nCr: 3n: 1, r: 1Worth of nCr: 1n: 8, r: 0Worth of nCr: 1n: 4, r: 4Worth of nCr: 1``

## Java Program to Calculate the Worth of nCr

Beneath is the Java program to calculate the worth of nCr:

``// Java program to calculate the worth of nCrpublic class Principal{// Operate to calculate the factorial of a quantitystatic int factorial(int num) {if (num <= 1) {return 1;}return num * factorial(num - 1);}// Operate to calculate the worth of nCrstatic int calculate_nCr(int n, int r) {return factorial(n) / (factorial(r) * factorial(n - r));}public static void principal(String[] args) {int n1 = 10;int r1 = 5;System.out.println("n: " + n1 + ", r: " + r1);System.out.println("Worth of nCr: " + calculate_nCr(n1, r1));int n2 = 3;int r2 = 2;System.out.println("n: " + n2 + ", r: " + r2);System.out.println("Worth of nCr: " + calculate_nCr(n2, r2));int n3 = 1;int r3 = 1;System.out.println("n: " + n3 + ", r: " + r3);System.out.println("Worth of nCr: " + calculate_nCr(n3, r3));int n4 = 8;int r4 = 0;System.out.println("n: " + n4 + ", r: " + r4);System.out.println("Worth of nCr: " + calculate_nCr(n4, r4));int n5 = 4;int r5 = 4;System.out.println("n: " + n5 + ", r: " + r5);System.out.println("Worth of nCr: " + calculate_nCr(n5, r5));}}``

Output:

``n: 10, r: 5Worth of nCr: 252n: 3, r: 2Worth of nCr: 3n: 1, r: 1Worth of nCr: 1n: 8, r: 0Worth of nCr: 1n: 4, r: 4Worth of nCr: 1``

## Conclusion

On this article, you discovered calculate the worth of nCr in several programming languages. The method is similar, and transfers properly between languages.

Permutations and combos are the rules of counting utilized in numerous conditions. You possibly can calculate the worth of nPr utilizing an identical strategy.

How to Calculate the Value of nPr Using Functions

These algorithms help you calculate the value of nPr using the permutation formula.