- 1

i need To fil an array with randoms between two nembers given by thé user

for exemple t[i]= a + (rand()%b);but the compilateur doesnt accept it

1st Oct 2016, 9:02 PM
boutheina
2 Respostas
0
no i want to use the rand () function to feel an array with randoms between two variables
2nd Oct 2016, 9:11 AM
boutheina
0
you can do something like this. int *fillArrayWithRandomNumbers(int arraySize, int lowerBound, int upperBound) { int range = upperBound - lowerBound; int *intArray = new int[arraySize]; for (int i = 0; i < arraySize; i++) { intArray[i] = (rand() % range) + lowerBound; } return intArray; } and call it like this: int *array = fillArrayWithRandomNumbers(25, 100, 500);
6th Oct 2016, 5:44 AM
Edwin Lingad
Edwin Lingad - avatar