60 537
Assignments Done
97,9%
Successfully Done
In April 2018

# Answer to Question #50007 in C for soumya

Question #50007
You have a block of platinum that can be exchanged in your bank either for cash
or for smaller blocks of platinum. If you exchange a block of m grams, you get
three blocks of weight m/2, m/3 and m/4 grams each. You don't get any fractional
part, as the division process rounds down the value. If you exchange the block of
platinum for cash, you get m units of currency. You can do any number of
exchanges for smaller blocks or currency.Given the value of a block in grams as input, write a program that would print the largest possible currency value that you can receive as the output. Assume that
the maximum value of a block that can be given as an input is 1,000,000,000
grams and the minimum value is 2 grams.
Program
&nbsp;
#include &lt;iostream&gt;
#define MIN_SIZE 2
&nbsp;
using namespace std;
&nbsp;
//cost of pieces size m
//calc recursive
double cost(int m)
{
&nbsp;&nbsp;&nbsp;//bottom of recursion - minimal size less MIN_SIZE
&nbsp;&nbsp;&nbsp;//i.e. m~m/2+m/3+m/4; m/4&lt;2 or m&lt;8
&nbsp;&nbsp;&nbsp;if(m&lt;8)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return m;
&nbsp;&nbsp;&nbsp;else
&nbsp;&nbsp;&nbsp; {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//check: is round of dividing less pieces?
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if((m/2+m/3+m/4)&lt;m)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return m;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return cost(m/2)+cost(m/3)+cost(m/4);
&nbsp;&nbsp;&nbsp; }
}
int main( )
{
int m;
cout&lt;&lt;&quot;Input weight block ofplatinum (g): &quot;;
cin&gt;&gt;m;
return 0;
}
&nbsp;
Example of execute program:
Input weight block of platinum (g): 24
You can receive currency value: 27
&nbsp;
Input weight block of platinum (g): 10
You can receive currency value: 10
﻿

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!