Sunday 15 March 2015

Program to find NCR value of the given numbers Using C

# include <stdio.h>
# include <conio.h>

long fact(int) ;

void main()
{
long i, ncr ;
int n, r ;
clrscr() ;
printf("Enter the value for N : ") ;
scanf("%d", &n) ;
printf("\nEnter the value for R : ") ;
scanf("%d", &r) ;
if(n >= r)
{
ncr = fact(n) / (fact(n-r) * fact(r)) ;
printf("\nThe NCR value is : %ld", ncr) ;
}
else
printf("\nCalculating NCR value is not possible") ;
getch() ;
}
long fact(int i)
{
long x ;
if(i == 0)
return 1 ;
else
{
x = i * fact(i - 1) ;
return x ;
}
}

RUN 1 :
~~~~~~~
Enter the value for N : 7
Enter the value for R : 5
The NCR value is : 21

RUN 2 :
~~~~~~~
Enter the value for N : 5
Enter the value for R : 7
Calculating NCR value is not possible

No comments:

Post a Comment