#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

#### Categories

Welcome to the new platform of Programmers Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use it's exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

# Help for school C project

Posts: 1Member
Thats the object:

Make a C program that performs reading from the keyboard of a real number N determines the size of a matrix N x N and seeking the maximum value among the sums recovered separately for each line parallel to the primary diagonal.

I wrote this program but it isn't working how it should do. For example if i write the matrix 1 2 3 4 5 6 7 8 9 the maximum value should be the sum of the primary diagonal (1 5 9 = 16), but the program says 1982684092. Help me please :)

#include

int main () {

int N, i, j, sum_a, sum_b, sum_max;

printf("Enter a real number that define the matrix's size:");
scanf("%d", &N);

int a[N][N];
for (i = 0; i < N; i++)
{
for (j = 0; j < N; j++)
{
printf("Enter[%d][%d]: ", i, j);
scanf("%d", &a[i][j]);
}
}

for (i = 0; i < N; i++)
{
int sum_a = 0;
int sum_b = 0;

for (j = 0; j + i < N; j++)
{
sum_a += a[i + j][j];
sum_b += a[j][i + j];

}

if (sum_a < sum_b)
sum_a = sum_b;

if (sum_max < sum_a)
sum_max = sum_a;
}

printf("sum_max: %d
", sum_max);

return 0;

}
· ·