main.c

Code:

#include <stdio.h>
#include <stdlib.h>
#include "himplementation.h"
int main(int argc, char *argv[])
{
int n, m, k, j;
scanf("%d %d", &n, &m);
int inp[n][m];
for (k = 0; k < n; k++) {
for (j = 0; j < m; j++) {
scanf("%d", &inp[k][j]);
}
}
printf("\n");
for (k = 0; k < n; k++) {
for (j = 0; j < m; j++) {
sum(n, m, k, j, inp);
}
}
// for (k = 0; k < n; k++)
// free(*(input+k));
// free(input);
return 0;
}

function implementation.c

Code:

#include <stdio.h>
#include "hfiles.h"
int sum(int n, int m, int k, int j, int input[n][m])
{
int maxsum, max;
max = 0;
maxsum = 0;
if (k == n-1) {
while (j < m-1) {
if (input[k][j] > max) {
max = input[k][j];
}
j++;
}
maxsum = input[k][j] + max;
max = 0;
}
else if (k < n && j == 0) {
if (input[k+1][0] > max)
max = input[k+1][0];
printf("max1 = %d, input[i+1][0] = %d\n", max, input[k+1][0]);
if (input[k+1][1] > max)
max = input[k+1][1];
printf("max2 = %d, input[i+1][1] = %d\n", max, input[k+1][1]);
if (input[k+1][m-1] > max)
max = input[k+1][m-1];
printf("max3 = %d, input[i+1][m] = %d\n", max, input[k+1][m-1]);
maxsum = input[k][j] + max;
max = 0;
}
else if (k < n && (j > 0 && j < m-1)) {
if (input[k+1][j-1] > max)
max = input[k+1][j-1];
if (input[k+1][j] > max)
max = input[k+1][j];
if (input[k+1][j+1] > max)
max = input[k+1][j+1];
maxsum = max + input[k][j];
max = 0;
}
else if (k < n && j == m-1) {
if (input[k+1][m-2] > max)
max = input[k+1][m-2];
if (input[k+1][m-1] > max)
max = input[k+1][m-1];
if (input[k+1][0] > max)
max = input[k+1][0];
maxsum = max + input[k][j];
max = 0;
}
printf("%d, max = %d, maxsum = %d\n", input[k][j], max, maxsum);
//sum(n, m, i, j+1, input);
}

prototype of function:

Code:

int sum(int, int, int, int, int);