Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to choose the best marks with specified credits in c programming?
    primarykey
    data
    text
    <p>I want to make a program to get the weighted average (<code>formula = (mark*(credits corresponds to it))/total credits</code>) from the <code>best(highest) 120 credits module</code> from the following marks and credits (the credits corresponds to the module):</p> <pre><code>module[12]={48, 77, 46, 82, 85, 43, 49, 73, 65, 48, 47, 51} credits[12]={60, 20, 20, 20, 10, 20, 10, 10, 10, 20, 20, 10} </code></pre> <p>What I have done is bubble sort the array, so that the array is sorted by decreasing manner to know which marks is higher, as shown below: </p> <pre><code>module[12]={85, 82, 77, 73, 65, 51, 49, 48, 48, 47, 46, 43} credits[12]={10, 20, 20, 10, 10, 10, 10, 60, 20, 20, 20, 20} </code></pre> <p>And then I need to choose the best 120 credits module from the sorted array <strong>so that the weighted average will be maximum</strong>, but then I have no idea where to start. =(</p> <p>Someone help me! Thanks a lot!</p> <p>EDIT: I have tried to work out the code myself, and eventually get the following code, it works, but for some special case it stop working =(</p> <pre><code>float credits=0, result=0; n=0; struct{ float credits; float result; float n; float addpoint; }point; while (credits &lt; 120){ credits+=credits[n]; result+=(result[n]*credits[n]); n++; } if (credits != 120){ credits -= credits[n-1]; result -= (result[n-1]*credits[n-1]); point.credits = credits; point.result = result; point.n = (n-1)-1; point.addpoint = n; again: while (credits &lt; 120){ credits+=credits[n]; result+=(result[n]*credits[n]); n++; } if (credits != 120){ point.credits -= credits[point.n-1]; point.result -= result[point.n-1]*credits[point.n-1]; point.n--; credits = point.credits; result = point.result; n = point.addpoint-1; goto again; } } </code></pre> <p>EDIT:</p> <p>Solved. Using knapsack problem code/integer linear programming by the application of glpk</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload