dimanche 25 octobre 2020

Issue with rand() function and matrices [closed]

I'm trying to build a programm where i have a 4x3 matrix filled with random numbers (using the rand() function) but when i try to visualize the matrix, it is empty. It seems that the path never enters the first (and second) for{}.

The code is

#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;
int main()
{
    srand(time(NULL));
    const int nr=4,nc=3;
    int mat[nr][nc];
    for(int i=0; i++; i<nr)
    {
        for(int j=0; j++; j<nc)
        {
            mat[i][j]=rand();
            cout<<mat[i][j]<<endl; // ! doesn't do anything..
        }
    }   

    cout<<"MATRIX:"<<endl;
    for(int i=0;i++;i<nr)
    {
        for(int j=0;j++;j<nc)
            cout<<mat[i][j];
        cout<<endl;
    }
    system("pause");
}



Aucun commentaire:

Enregistrer un commentaire