B
B
brrrrrrrrr2020-11-10 18:40:42
C++ / C#
brrrrrrrrr, 2020-11-10 18:40:42

How to set a matrix in C++?

How to fill a matrix with random numbers.
Display the main i side diagonal symmetrically
about the horizontal axis?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergo Zar, 2020-11-10
@Sergomen

// потрібні бібліотеки:
#include <iomanip>
#include <cstdlib>
#include <ctime>
//....
srand(time(0));
int A[3][3]; // матриця 3 на 3
/* матриці задаються двомірними масивами */
//заповнення рандомом
for (int i = 0; i < 3; i++){
    for (int j = 0; j < 3; j++){
         A[i][j] = rand() % 100 + 1; // 100 максимум, 1 - мінімум
         cout << setw(3) << A[i][j] << " ";
         if(j >= 3 -1){
              cout << endl;
         }
    }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question