Created
January 31, 2022 09:00
-
-
Save ProfAndreaPollini/3d5446fb216716a9906ba27ae09ce382 to your computer and use it in GitHub Desktop.
Inizializzare gli elementi di una matrice in C++ a valori randomici compresi tra zero e dieci(escluso)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <cstdlib> | |
#include <ctime> | |
/* | |
Inizializzare gli elementi di una matrice in C++ a valori randomici compresi tra zero e dieci(escluso) | |
*/ | |
const int RIGHE = 10; | |
const int COLONNE = 15; | |
int main() { | |
int mat[RIGHE][COLONNE]; | |
// init rng | |
std::srand(std::time(nullptr)); | |
for(auto r = 0 ; r < RIGHE; r++) { | |
for(auto c = 0; c< COLONNE; c++ ) { | |
mat[r][c] = std::rand() % 10; | |
} | |
} | |
for(auto r = 0 ; r < RIGHE; r++) { | |
for(auto c = 0; c< COLONNE; c++ ) { | |
std::cout << mat[r][c] << " "; | |
} | |
std::cout << "\n"; | |
} | |
std::cout << "\nbye.\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment