1. 2d matrix beginner.

Hi, I am trying to do some exercises to learn 2d matrices in c. My goal is to create a 2d matrix which has only 3 columns but the user defined raws lets say "x" raws. The second column must contain the second exponent of the first column-numbers and the third column must contain the third exponent of the first column.

1 1^2 1^3
2 2^2 2^3
3 3^2 3^3
. . . . .
. . . . .
x x^2 x^3

This is exactly what I am trying to write. I have started to code but now I am stuck. Can anyone help me with any advice? I will post my code in the first answer.

2. This is how far I have come:

1 1 1
2 2 2
3 3 3

This is the code:

insert
Code:
```#include <stdio.h>
#include <stdlib.h>

int main(void)
{

int m[3][3];
int i, j;
for(i=0;i<3;i++){
for(j=0;j<3;j++){
m[i][j] = i+1;
printf("%i\n", m[i][j]);
}
}
printf("Content of the 2 D Array: \n");
for(i=0;i<3;i++){
for(j=0;j<3;j++){
printf("%4d", m[i][j]);}
printf("\n");
}

return 0;
}```

3. Originally Posted by hekk_tech
Hi, I am trying to do some exercises to learn 2d matrices in c. My goal is to create a 2d matrix which has only 3 columns but the user defined raws lets say "x" raws. The second column must contain the second exponent of the first column-numbers and the third column must contain the third exponent of the first column.

1 1^2 1^3
2 2^2 2^3
3 3^2 3^3
. . . . .
. . . . .
x x^2 x^3

This is exactly what I am trying to write. I have started to code but now I am stuck. Can anyone help me with any advice? I will post my code in the first answer.

Matrices can be hard to understand. It's easier when you think of them as something concrete rather than an abstract "matrix". When I'm teaching matrices, I use football as an example. Say you've got four teams, three competitions, and results for those three competions (ranks). Which team is best? Well we'd rank the league cup above the FA cup, and the Champion's league top of all. So that gives us three weights, say two for the FA cup, five for the league, eight for the Chamipon's league So you can see naturally how we obtain a final score for each team.

But what weights to use? I ask two or three people around the class for their weights. That gives me a 3xN matrix of weights. Then we've got matrix to matrix multiplication.

The code to multiply two matrices in C is in fact extremely easy to write. The problem is wholly in understandign what you are doing.

4. I thought it was just a 2D array of some number of rows initialised with
x, pow(x,2), pow(x,3)

5. Originally Posted by Malcolm McLean
Matrices can be hard to understand. It's easier when you think of them as something concrete rather than an abstract "matrix". When I'm teaching matrices, I use football as an example. Say you've got four teams, three competitions, and results for those three competions (ranks). Which team is best? Well we'd rank the league cup above the FA cup, and the Champion's league top of all. So that gives us three weights, say two for the FA cup, five for the league, eight for the Chamipon's league So you can see naturally how we obtain a final score for each team.

But what weights to use? I ask two or three people around the class for their weights. That gives me a 3xN matrix of weights. Then we've got matrix to matrix multiplication.

The code to multiply two matrices in C is in fact extremely easy to write. The problem is wholly in understandign what you are doing.

Very well you have successfully pointed out that I do not understand matrices. But this information was already obvious, otherwise I wouldn't register on this forum to ask for help and not to hear you letting me know that I do not know what I am doing. Of course I do not know what I am doing and I want to learn, please can anyone show me how its done?

6. As I said
Code:
`m[i][j] = pow(i+1,j+1);`
pow() is in math.h

7. Originally Posted by Salem
As I said
Code:
`m[i][j] = pow(i+1,j+1);`
pow() is in math.h
m[i][j] = pow(i+1,j+1)+0.5;
... just to be sure...

8. Just for an update this is where I am at with this problem right now. Still no success, but I am definitely closer.

insert
Code:
```#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main()
{
int x, i, j;
do {
printf("Insert Value for x: \n");
scanf("%d", &x);
} while (x<=1 || x>=21);
int m[x][3];
for (i=0; i<x; i++){
for (j=0; j<3; j++){
m[i][j] = pow (i+1, j+1);
}
}
return 0;
}```

9. Ok after a couple of ours of googling and trial and error I have finally succeeded my first "difficult" exercise. Thanks @hamster_nz and Salem for your advices. I am posting here the final result.

insert
Code:
```#include <stdio.h>#include <stdlib.h>
#include <math.h>

int main()
{
int x, i, j;
do {
printf("Insert Value for x: \n");
scanf("%d", &x);
} while (x<=1 || x>=21);
int array[21][21];
for (i=0; i<x; i++){
for (j=0; j<3; j++){
array[i][j] = pow (i+1, j+1);
}
}

printf("Two Dimensional array elements:\n");
for(i=0; i<x; i++){
for(j=0; j<3; j++){
printf("%d ", array[i][j]);
}
printf("\n");
}
return 0;
}```