Matrix

Jun 1, 2016 at 2:00pm
NVM

close or delete
Last edited on Jun 1, 2016 at 4:02pm
Jun 1, 2016 at 2:42pm
closed account (48bpfSEw)
Break down your problem in little problems.

1. you need a place for your matrix:

 
int matrix[5][5];


2. Initialize the matrix (clear its content). In this case not realy important.

1
2
3
for (int x=0;x<5;x++)
  for (int y=0;y<5;y++)
    matrix[x][y] = 0;


3. Now the engine or heard of your code. Write a function which gives you the next number of the row!

1
2
3
4
5
6
7
int fn(int value) {
  value ++;
  if (value > 5)
    value = 1;

  return value;
  }



4. Now you can fill your matrix

1
2
3
4
5
6
7
for (int x=0;x<5;x++) {
  int value = x+1;  // starting first number of the row with 1 until 5
  for (int y=0;y<5;y++) {
    value = fn(value);
    matrix[x][y] = value;
    }
  }

Topic archived. No new replies allowed.