Question

Write a C code for Modified Change problem: Apply the dynamic programming algorithm to find all...

Write a C code for

Modified Change problem:

Apply the dynamic programming algorithm to find all the solutions to the change-making problem for the denominations 1, 3, 5 and the amount n = 9

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Total 6 solutions are possible, and they are The coins which we have {1, 3, 5} With max number of coins of 5 the denomination

Code in c

1 #include<stdio.h> #include<string> 2 3 4 int possiblewayschangeorder(int changemakingcoinorder[], int dcoinssize, int n); i

#include<stdio.h>

#include<string>

int possiblewayschangeorder(int changemakingcoinorder[], int dcoinssize, int n);

int main()

{

    int denominationcoins[] = {1, 3, 5};

    int dcoinssize = sizeof(denominationcoins) / sizeof(denominationcoins[0]);

    int n = 9;

    printf("%d", possiblewayschangeorder(denominationcoins, dcoinssize, n));

    return 0;

}

int possiblewayschangeorder(int changemakingcoinorder[], int dcoinssize, int n)

{

    int coin, making;

    int changemaking[n + 1][dcoinssize];

    for (int i = 0; i < dcoinssize; i++)

        changemaking[0][i] = 1;

    for (int i = 1; i < n + 1; i++)

    {

        for (int j = 0; j < dcoinssize; j++)

        {

            coin = (i - changemakingcoinorder[j] >= 0) ? changemaking[i - changemakingcoinorder[j]][j] : 0;

            making = (j >= 1) ? changemaking[i][j - 1] : 0;

            changemaking[i][j] = coin + making;

        }

    }

    return changemaking[n][dcoinssize - 1];

}\

PLEASE LIKE IT RAISE YOUR THUMBS UP
IF YOU ARE HAVING ANY DOUBT FEEL FREE TO ASK IN COMMENT SECTION

Add a comment
Know the answer?
Add Answer to:
Write a C code for Modified Change problem: Apply the dynamic programming algorithm to find all...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT