Create N matrices simultaneously.

closed account (GbX4GNh0)
I would like to create N matrices of dimension (n,k) simultaneously. Lets say for example that N=3. Could you please help me. I read the command a[n][k][N] but I don't understand how to use it.

Please help me, I know that for some of you this question is silly but I' m new to this language and I have noone else to ask.
There are no "commands" in C++.

There are statements and expressions (instructions and calculations), and there is data (and data types).

It is simplest if you try not to think of it all at once:

1
2
#include <iostream>  // C++
using namespace std;
 
#include <stdio.h>  // C 
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
36
37
38
39
40
const int n = 3;
const int k = 4;

// A matrix data type
typedef double matrix_t[n][k];

// A function that works on a matrix
void print_matrix( matrix_t M )
{
  for (int ni = 0; ni < n; ni++)
  {
    for (int ki = 0; ki < k; ki++)
    {
      // cout << M[ni][ki] << "\t";  // C++
      // printf( "%lf\t", M[ni][ki] );  // C
    }
    //cout << "\n";  // C++
    //puts( "" );  // C
  }
}

int main()
{
  // Some matrices to play with
  matrix_t one_matrix;
  matrix_t many_matrices[ 10 ];

  // Assign values to your matrices here.
  ...

  // Now let's display our stuff to the user.
  print_matrix( one_matrix );

  for (int i = 0; i < 10; i++)
  {
    print_matrix( many_matrices[i] );
  }

  return 0;
}

Hope this helps.
Topic archived. No new replies allowed.