COMBINATION OF CROPS
Combination Of Crops
John is a young farmer. He practiced precision farming in turmeric and he sowed the turmeric rhizomes after plowing the land well. He also grew onion, coriander, chilies, and red gram as intercrops. He got high yield by using sufficient water and fertilizers at a correct time.
From the profit, he purchased N number of fields.So he is planning to grow different crops in that purchased fields.
There are 'n' fields and 'r' crops. Help him to find the total number of different combinations in which the crops can be planted in the purchased fields.
Hint: Use the formula nCr = (n-1)Cr+(n-1)C(r-1).
Note:
Function name: int combination(int n,int r);
Input Format:
The first input is an integer which corresponds to the 'n' value indicates a number of fields.
The second input is an integer which corresponds to the 'r' value indicates a number of crops.
Output Format:
The output is an integer that corresponds to the number of ways in which the crops can be planted the fields.
Sample Input:
6 4
Sample Output:
15
#include
int combination(int n,int r);
int main()
{
int n,r;
scanf("%d%d",&n,&r);
printf("%d",combination(n,r));
return 0;
}
int combination(int n,int r)
{
if(r==0||r==n)
return 1;
else
return (combination(n-1,r-1)+combination(n-1,r));
}
Comments
Post a Comment