← Back to topics
Topic

Help-MATRIX

g
gigac
Hi...It's me again :)
I need help..
I want to create an algorithm to sum numbers in Matrix from 1,1 to 2,5.. I created something, but it doesn't sum the last number (doh) :? Can someone help me :? :? :?
m
marveringius

int matrix[3][6];
fill(matrix, 3, 6);
int sum = 0;
for(int i = 1; i <= 2; i++)
for(int j = 1; j <= 5; j++)
sum += matrix[i][j];

Was that what you want?
m
marveringius
this function called "fill()" was just an abstraction, ok? it doesn't exist in C++.
it's something like: "fill the matrix with random values or whatever you want"
g
gigac
Hm..It doesn't working.
What happens if I want to sum the numbers from [3,1] to [3,3]...It will also sum [1,1] and [2,1]..but I want to cross over that two numbers and to start summing from [3,1]
:X
g
gigac
Okay...I solve it.
Thanks anyway :))))