FACTORIAL
Factorial
A farmer used to grow the same crop every year. This year because of better water availability, he decides to grow different crops. He doesn't know how to arrange those crops in the field. Assume the number of distinct crops he wants to grow is N.
Can you help the farmer to find the total number of ways N distinct crops can be arranged in the field?
Note : Formulate a RECURSIVE Algorithm
Function name: int nWays(int n);
Input Format:
Input consists of a single integer N.
Output Format:
Refer the sample output for specification.
Sample Input:
5
Sample Output:
120 ways
#include
int nWays(int n)
{
if(n>=1)
return(n*nWays(n-1));
else
return 1;
}
int main()
{
int N;
scanf("%d",&N);
printf("%d ways",nWays(N));
return 0;
}
Comments
Post a Comment