Multiplication of C++ matrices

Asked

Viewed 338 times

0

I am making a program in C++ that allows the multiplication of 2 matrices, my problem is that I did not want to have to predefine the size of each matrix, so I used the following code:

    int ia, ib, ja, jb, ic, jc;
    float matriz_A[ia] [ja], matriz_B[ib][jb], matriz_C[ic][jc];

    printf("Escolheu input por TECLADO");
    printf("\n==========================");
    printf("\n\nLeitura de dados");
    printf("\n===================");
    printf("\n\nIndique o tipo de matriz que pretende inserir ['i' e 'j']");

but the code contains errors, how can I fix the problem?

Objective: Make the user choose the i and j of each matrix. O wanted matrix C to have dimensao ic and jc according to matrix A and B Thank you from now on.

1 answer

1

In the first point, you are using the value of the variables ia, ib, ja, jb, ic, jc before populating them. So they have only garbage and their program has erratic behavior.

If you really want to test the program, initially I strongly recommend that you do not start with the interface in the middle of the tests. What do I mean by that? Let me explain better in the paragraph below.

So far, you’ve shown 7 lines of code, two of which are just variable statements and the other 5 are interface messages. Of those 7 lines, you can say that only the 2 variable declaration lines refer to your goal, but they also don’t bring you any closer to it. See, you haven’t even started matrix multiplication yet! It’s still populating the data by the interface!

Leave to do the interface at a later time, focus soon on your real problem and, after it is solved, you can worry about an interface to receive data.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.