In this tutorial you will learn about the C program to find NCR Factorial of a Number and its application with practical example.
C program to find NCR Factorial of a Number
In this tutorial, we will learn to create a C program that will find NCR Factorial of a Number using C programming.
Prerequisites
Before starting with this tutorial, we assume that you are the best aware of the following C programming topics:
- Operators in C Programming.
- Basic Input and Output function in C Programming.
- Basic C programming.
- For Loop in C programming.
- Arithmetic operations in C Programming.
Algorithm:-
1 2 3 4 5 6 7 8 9 |
1. Declaring the required variables for the program. 2. Taking the input number N and R from the user. 3. Using the <b>for loop to find the factorial</b>. 4. Printing the factorial to the user. 5. End the Program. |
Finding the NCR Factorial of a number:-
In this program, we will take the input numbers N and R from the user. Then we will pass that number to a for loop to calculate the factorial. Then we will print that factorial for N & R using the printf() function.
With the help of the below program, we can find the NCR Factorial of a Number.
Program Code:-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
/* C Program to Find NCR Factorial of a Number */ #include <stdio.h> int Cal_Fact(int); int main() { //declaring the required variables for the program. int no, re, ncr; //i = it will hold the integer value for the loop. //start = it will hold the input integer value from the user. /* Taking the Input N and R from user */ printf("\n Please Enter the Values for N and R: \n"); //scanning the user input. scanf("%d %d", &no, &re); //Calculating the ncr factorial ncr = Cal_Fact(no) / (Cal_Fact(re) * Cal_Fact(no-re)); //Printing the NCR Factorial to the user. printf("\n NCR Factorial of %d and %d = %d", no, re, ncr); return 0;// return 0 to operating system } //Function to find the factorial. int Cal_Fact(int Number) { int i; int Factorial = 1; for (i = 1; i <= Number; i++) { Factorial = Factorial * i; } return Factorial; } |
Output:-
In the above program, we have first initialized the required variable.
- no= it will hold the integer value for the input.
- re = it will hold the integer value for the input.
- i = it will hold the integer value for the controlling of the loop.
Taking the input N and R number from the user.
Converting the factorial for the number.
Printing output.