Program to find NCR value of the given numbers
Program:
#include<stdio.h>
#include<conio.h>
long fact(int);
void main()
{
long i, ncr;
int n, r;
clrscr();
printf("Enter the value for N : ");
scanf("%d", &n);
printf("\nEnter the value for R : ");
scanf("%d", &r);
if(n >= r)
{
ncr = fact(n) / (fact(n-r) * fact(r));
printf("\nThe NCR value is : %ld", ncr);
}
else
printf("\nCalculating NCR value is not possible");
getch();
}
long fact(int i)
{
long x;
if(i == 0)
return 1;
else
{
x = i * fact(i - 1);
return x;
}
}
Output:
Case: 1
Enter the value for N : 7
Enter the value for R : 5
The NCR value is : 21
Case: 2
Enter the value for N : 5
Enter the value for R : 7
Calculating NCR value is not possible
-
UpdatedDec 30, 2019
-
Views7,492
You May Like
Program to maintain employee details using structures
Program to maintain student details using structures
Check whether the person is eligible to vote or not
Print the numbers that are divisible by a given no.
Program to generate magic square
To sort the given numbers in ascending & descending order