This question already has an answer here:
Could you help me? I need for my matrix multiplication code random values between -10 and 10. How can I do it? Here is my code
#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;
#define CAPACITY 30
struct Matrix
{
int row, col;
int** matrix;
Matrix() {//Creates complete randomized matrix
row = rand() % 10 + 1;
col = rand() % 10 + 1;
matrix = new int*[row];
for(int i = 0; i < row; i++) matrix[i] = new int[col];
for(int i = 0; i < row; i++) {
for(int j = 0; j < col; j++) matrix[i][j] = rand()%CAPACITY + 1;
}
Aucun commentaire:
Enregistrer un commentaire