Ad

Monday, August 19, 2013

Coin Distribution Problem

Coin Distribution by Using C Program

          Problem:- Suppose, You have 100 coins which need to be distributed among 3 beggars A, B, C. In how many ways can you distribute these 100 coins among the 3 beggars ? Constraint: A cannot have more than 75 coins, B cannot have more than 50 coins, and C cannot have more than 25 coins.

 We can solve this problem by writing a simple code in C. The code is here.............

 

Solution:-

#include<stdio.h>

int main ()
{
    int a, b, c, count=0;

    for(b=1;b<=50;b++)
    {
    for(c=1;c<=25;c++)
    {
        if(b+c>=25)
        {
            count++;
        }
    }
}

printf("The Maximum ways of distribution : %d.", count);

return 0;
}

0 comments:

Post a Comment