matrix algorithm

The exercise says:

You have a NxN matrix with numbers from 1 to N (unsigned integers), it doesn't matter that any block has the same number, the target is that the addition of three following blocks be equal to M (unsigned integer), the additions must be like the image.

Image: http://img31.imageshack.us/img31/9140/dibujohqt.jpg

Any help?

PD: I've got this (without the algorithm):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <iostream.h>
#include <stdlib.h>
#define NMAX 6

void main(){
	unsigned int arreglo[NMAX][NMAX];
	unsigned int conta = 1;
	int suma1 = 0, suma2 = 0, suma3 = 0;
	for(int i = 0; i < NMAX; i++){
		for(int j = 0; j < NMAX; j++){
			arreglo[i][j] = conta++;
		}
	}
	for(int i = 0; i < NMAX; i++){
		for(int j = 0; j < NMAX; j++){
			cout << arreglo[i][j] << "\t";
		}
		cout << "\n";
	}
	for(int i = 0; i < 3; i++){
		int j = 0;
		suma1 += arreglo[i][j];
	}
	for(int j = 3; j < NMAX; j++){
		int i = 4;
		suma2 += arreglo[i][j];
	}
	int i = 3, j = 2;
	do{
		suma3 += arreglo[i][j];
		i++; j--;
	}while(i < NMAX && j >= 0);
	cout << "\n" << suma1 << ", " << suma2 << ", " << suma3;
	cout << "\n"; system("PAUSE");
}
It looks like you are doing what you need to.

What is the question? How are you supposed to build the matrix?
Hi again, what i need is the algorithm to generate a magic cube of 6x6, nothing else, if anyone knows where it's, tell me please.

Thanks.
Thank you, i'll try.
Topic archived. No new replies allowed.