#include<stdio.h>
#include<stdlib.h>
long fact(int n)
{
if(n==0 || n==1)
return 1;
else
return (n*fact(n-1));
}
long ncr(int n,int r)
{
return(fact(n)/(fact(r)*fact(n-r)));
}
long npr(int n,int r)
{
return(fact(n)/fact(r));
}
void main()
{
int f,r;
long f1;
int n3;
printf("\n Enter the value of n=");
scanf("%d",&f);
while(1)
{
printf("\n Press 1 for factrorial=");
printf("\n Press 2 for combination");
printf("\n Press 3 for permutation");
printf("\n Enter your choice=");
scanf("%d",&n3);
switch(n3)
{
case 1: f1=fact(f);
printf("%ld",f1);
break;
case 2: printf("\n Enter the value of r=");
scanf("%d",&r);
printf("\n Combination=%ld",ncr(f,r));
break;
case 3: printf("\n Enter the value of r=");
scanf("%d",&r);
printf("\n Permutation=%ld",npr(f,r));
break;
default: printf("\n Wrong choice");
exit(1);
}
}
}
#include<stdlib.h>
long fact(int n)
{
if(n==0 || n==1)
return 1;
else
return (n*fact(n-1));
}
long ncr(int n,int r)
{
return(fact(n)/(fact(r)*fact(n-r)));
}
long npr(int n,int r)
{
return(fact(n)/fact(r));
}
void main()
{
int f,r;
long f1;
int n3;
printf("\n Enter the value of n=");
scanf("%d",&f);
while(1)
{
printf("\n Press 1 for factrorial=");
printf("\n Press 2 for combination");
printf("\n Press 3 for permutation");
printf("\n Enter your choice=");
scanf("%d",&n3);
switch(n3)
{
case 1: f1=fact(f);
printf("%ld",f1);
break;
case 2: printf("\n Enter the value of r=");
scanf("%d",&r);
printf("\n Combination=%ld",ncr(f,r));
break;
case 3: printf("\n Enter the value of r=");
scanf("%d",&r);
printf("\n Permutation=%ld",npr(f,r));
break;
default: printf("\n Wrong choice");
exit(1);
}
}
}
No comments:
Post a Comment