This program finds the NCR ( to calculate combinations). The program displays the output when the values of n and r are provided. We have also created a function called facto to find the factorial of a number.
The equation is nCr = n! / r! * (n - r)!
The equation is nCr = n! / r! * (n - r)!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
int facto(int f) | |
{ | |
int fact = 1; | |
for(;f>0;f--) | |
{ | |
fact=fact*f; | |
} | |
return fact; | |
} | |
int main() | |
{ | |
int n,r; | |
float s; | |
printf("n == "); | |
scanf("%d",&n); | |
printf("r == "); | |
scanf("%d",&r); | |
s = facto(n)/(facto(n-r) * facto(r)); | |
printf("%d C %d = %f ",n,r,s); | |
getch(); | |
return(0); | |
} |
Comments
Post a Comment