Vogel's approximation method: Difference between revisions
→{{header|C}}: Fixed bug - results (fortuitously!) unchanged. Also added second example.
(→{{header|C}}: Fixed bug - results (fortuitously!) unchanged. Also added second example.) |
|||
Line 77:
=={{header|C}}==
{{trans|Kotlin}}
<lang c>#include <stdio.h>
#include <limits.h>
Line 144 ⟶ 142:
int i, res1[4], res2[4];
max_penalty(N_ROWS, N_COLS, TRUE, res1);
max_penalty(N_COLS,
if (res1[3] == res2[3]) {
Line 197 ⟶ 195:
Total cost = 3100
</pre>
If the program is changed to this (to accomodate the second Ruby example):
<lang go>#include <stdio.h>
#include <limits.h>
#define TRUE 1
#define FALSE 0
#define N_ROWS 5
#define N_COLS 5
typedef int bool;
int supply[N_ROWS] = { 461, 277, 356, 488, 393 };
int demand[N_COLS] = { 278, 60, 461, 116, 1060 };
int costs[N_ROWS][N_COLS] = {
{ 46, 74, 9, 28, 99 },
{ 12, 75, 6, 36, 48 },
{ 35, 199, 4, 5, 71 },
{ 61, 81, 44, 88, 9 },
{ 85, 60, 14, 25, 79 }
};
// etc
int main() {
// etc
printf(" A B C D E\n");
for (i = 0; i < N_ROWS; ++i) {
printf("%c", 'V' + i);
for (j = 0; j < N_COLS; ++j) printf(" %3d", results[i][j]);
printf("\n");
}
printf("\nTotal cost = %d\n", total_cost);
return 0;
}</lang>
then the output, which agrees with the Phix output but not with the Ruby output itself is:
<pre>
A B C D E
V 0 0 461 0 0
W 277 0 0 0 0
X 1 0 0 0 355
Y 0 0 0 0 488
Z 0 60 0 116 217
Total cost = 60748
</pre>
|