Answer to Question #235911 in C for Rhea

Question #235911
Give a number of mangoes and number of persons . Find the number of ways to distribute the identical mangoes among identical persons
1
Expert's answer
2021-09-11T23:39:36-0400


#include <stdio.h>


int binomial_coefficient(int p, int m)
{
    int r = 1;
 
    if (m > p - m)
        m = p - m;
 
    for (int i = 0; i < m; ++i) {
        r *= (p - i);
        r /= (i + 1);
    }
 
    return r;
}


int calculate_ways(int m, int p)
{
    if (m < p)
        return 0;
    int ws = binomial_coefficient(p + m - 1, p - 1);
    return ws;
}
 
int main()
{
    int m = 4, p = 3;
 
    int res = calculate_ways(m, p);
    printf("%d\n", res);
 
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS