/*...................................................................................................................................................
file name: rec13.c
program :Function sub program to find the factorial of a number and use that
function to find the nCr(ncr=n!/(n-r)|*r!)
Author : sujithbaby440@gmail.com
Date : 15-11-14
...................................................................................................................................................*/
#include<stdio.h>
long fnFact(int n);
main()
{
int n,r,i,a[10];
long ncr,factn,factr,factnr,nr;
system("clear");
printf("The progranm to find the factorial and ncr\n\n");
printf("Input the values of n and r\n");
scanf("%d\n%d",&n,&r);
nr=n-r;
factn=fnFact(n);
printf("factn= %d\n",factn);
factr=fnFact(r);
printf("factr= %d\n",factr);
factnr=fnFact(nr);
printf("factnr= %d\n\n",factnr);
ncr=factn/(factnr*factr);
printf("ncr= %ld ",ncr);
}
long fnFact(int n)
{
int i;
long fact=1;
for(i=1;i<=n;i++){
fact=fact*i;
}
return fact;
}
OUTPUT 1
The progranm to find the factorial and ncr
Input the values of n and r
9 5
factn= 362880
factr= 120
factnr= 24
ncr= 126 [141740@localhost ~]$
OUTPUT 2
The progranm to find the factorial and ncr
Input the values of n and r
7 4
factn= 5040
factr= 24
factnr= 6
ncr= 35 [141740@localhost ~]$
file name: rec13.c
program :Function sub program to find the factorial of a number and use that
function to find the nCr(ncr=n!/(n-r)|*r!)
Author : sujithbaby440@gmail.com
Date : 15-11-14
...................................................................................................................................................*/
#include<stdio.h>
long fnFact(int n);
main()
{
int n,r,i,a[10];
long ncr,factn,factr,factnr,nr;
system("clear");
printf("The progranm to find the factorial and ncr\n\n");
printf("Input the values of n and r\n");
scanf("%d\n%d",&n,&r);
nr=n-r;
factn=fnFact(n);
printf("factn= %d\n",factn);
factr=fnFact(r);
printf("factr= %d\n",factr);
factnr=fnFact(nr);
printf("factnr= %d\n\n",factnr);
ncr=factn/(factnr*factr);
printf("ncr= %ld ",ncr);
}
long fnFact(int n)
{
int i;
long fact=1;
for(i=1;i<=n;i++){
fact=fact*i;
}
return fact;
}
OUTPUT 1
The progranm to find the factorial and ncr
Input the values of n and r
9 5
factn= 362880
factr= 120
factnr= 24
ncr= 126 [141740@localhost ~]$
OUTPUT 2
The progranm to find the factorial and ncr
Input the values of n and r
7 4
factn= 5040
factr= 24
factnr= 6
ncr= 35 [141740@localhost ~]$
No comments:
Post a Comment