Wisdom Materials
Home
About Us
Our Clients
Careers
Services
Education
Jobs
News
Business
Health
Astrology
Entertainment
RealEstate
Devotion
Contact Us
C Programs
/ ncr C Program
ncr = n! / r! (n-r)!
Program
Copy text
#include
void main() { int n, r, ncr; printf("Enter n and r values:"); scanf("%d%d",&n,&r); ncr = calc_ncr(n, r); printf("n=%d r=%d ncr=%d\n", n, r, ncr); } int calc_ncr(int n, int r) { int result; result = factorial(n)/(factorial(r)*factorial(n-r)); return result; } int factorial(int n) { int temp, result = 1; for (temp = 1; temp <= n; temp++) result = result*temp; return result; }
Input
Enter n and r values: 5 2
Output
n=5 r=2 ncr=10
Home
Back