forked from srinirad/Test3Session2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathp3final.c
More file actions
38 lines (38 loc) · 658 Bytes
/
p3final.c
File metadata and controls
38 lines (38 loc) · 658 Bytes
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
38
#include<stdio.h>
int input_n_and_r(int *n,int *r)
{
printf("Enter the value of n: ");
scanf("%d",n);
printf("Enter the value of r :");
scanf("%d",r);
}
int ncr(int n,int r)
{
int nfact=1,rfact=1,nrfact=1,ncr; //nrfact is for (n-r)!
for(int i=1;i<=n;i++)
{
nfact*=i;
}
for(int j=1;j<=r;j++)
{
rfact*=j;
}
for(int k=1;k<=(n-r);k++)
{
nrfact*=k;
}
ncr=nfact/(rfact*nrfact);
return ncr;
}
void output(int n,int r,int result)
{
printf("The factorial of %d and %d is %d",n,r,result);
}
int main()
{
int a,b,result;
input_n_and_r(&a,&b);
result=ncr(a,b);
output(a,b,result);
return 0;
}