Created
January 31, 2022 08:54
-
-
Save ProfAndreaPollini/7424ba3766604ba0217dcf8fbb5ced4c to your computer and use it in GitHub Desktop.
C++ inizializzare un vettore di elementi casuale usando std::rand()
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> | |
const int N = 100; | |
int main() { | |
int arr[N]; | |
// init rng | |
std::srand(std::time(nullptr)); | |
for (int i=0;i< N ; i++) { | |
arr[i] = -5 + (std::rand() % 11); | |
} | |
for (int i=0;i< N ; i++) { | |
std::cout << arr[i] << " "; | |
} | |
std::cout << "\nbye.\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment