| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
I need to write and array of 10 numbers that puts in random numbers for those 10 values ... How would i write this?
Thanks |
|
#2
|
|||
|
|||
|
I had to do this recently, heres the function I used:
Code:
void fillArray (int array[size], int number)
{
srand((unsigned)time(0));
for(int i=0; i<number; i++)
array[i] = (rand()%100)+1;
}
The array size in your case should be 10 and in your case the varible "number" should also be 10. Keep in mind this function only generates numbers 1-100. |
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > Memory & arrays - How to write a random array? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|