Skip to content

Instantly share code, notes, and snippets.

@complxalgorithm
Created May 8, 2016 08:28
Show Gist options
  • Save complxalgorithm/10440e06a25478207fae4e5b107d7623 to your computer and use it in GitHub Desktop.
Save complxalgorithm/10440e06a25478207fae4e5b107d7623 to your computer and use it in GitHub Desktop.
C program to calculate nCr.
/*
* C program to Calculate the value of nCr
*/
#include <stdio.h>
int fact(int z);
void main()
{
int n, r, ncr;
printf("\n Enter the value for N and R \n");
scanf("%d%d", &n, &r);
ncr = fact(n) / (fact(r) * fact(n - r));
printf("\n The value of ncr is: %d", ncr);
}
int fact(int z)
{
int f = 1, i;
if (z == 0)
{
return(f);
}
else
{
for (i = 1; i <= z; i++)
{
f = f * i;
}
}
return(f);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment