#include<stdio.h>
#include<conio.h>
void main(){
long int n,i,r,factn=1,factr=1,factnr=1,npr,ncr;
clrscr();
printf("Enter positive integer value of n\n");
scanf("%ld",&n);
printf("Enter positive integer value of r\n");
scanf("%ld",&r);
if (n>r){
{
for (i=1;i<=n;++i)
factn=factn*i;
}
if (r>0){
for (i=1;i<=r;++i)
factr=factr*i;
}
if (n-r>0){
for (i=1;i<=n-r;++i)
factnr=factnr*i;
}
npr=factn/factnr;
ncr=npr/factr;
printf("ncr value = %ld and npr value = %ld",ncr,npr);
}
else {
printf("value of r(%ld) is greater than value of n(%ld)\n please try again",r,n);
}
getch();
}
No comments:
Post a Comment