- 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
2 Respuestas
0
no i want to use the rand () function to feel an array with randoms between two variables
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);