Write a c program to find out NCR factor of given number.
Write a c program to find out NCR factor of given number
#include<stdio.h>
int main(){
int n,r,ncr;
printf("Enter any two numbers->");
scanf("%d %d",&n,&r);
ncr=fact(n)/(fact(r)*fact(n-r));
printf("The NCR factor of %d and %d is %d",n,r,ncr);
return 0;
}
int fact(int n){
int i=1;
while(n!=0){
i=i*n;
n--;
}
return i;
}
Alogrithm:
In the mathematics nCr has defined as
nCr = n! /((n-r)!r!)
Write a c program to find out NCR factor of given number
#include<stdio.h>
int main(){
int n,r,ncr;
printf("Enter any two numbers->");
scanf("%d %d",&n,&r);
ncr=fact(n)/(fact(r)*fact(n-r));
printf("The NCR factor of %d and %d is %d",n,r,ncr);
return 0;
}
int fact(int n){
int i=1;
while(n!=0){
i=i*n;
n--;
}
return i;
}
Alogrithm:
In the mathematics nCr has defined as
nCr = n! /((n-r)!r!)
0 comments:
Post a Comment