Skip to content

Instantly share code, notes, and snippets.

@ProfAndreaPollini
Created January 31, 2022 08:54
Show Gist options
  • Save ProfAndreaPollini/7424ba3766604ba0217dcf8fbb5ced4c to your computer and use it in GitHub Desktop.
Save ProfAndreaPollini/7424ba3766604ba0217dcf8fbb5ced4c to your computer and use it in GitHub Desktop.
C++ inizializzare un vettore di elementi casuale usando std::rand()
#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