Stuck on a problem. Rand

Mar 14, 2013 at 1:10am
Write a program that picks 1000 random numbers between 0 and 10 and tells us how many of these were <5.

So when you run it might say:
I picked a 1000 random numbers between 0-10 and 443 of them were <5
Mar 14, 2013 at 1:22am
I guess creating an iterator that saves each randomized numbers in an integer array of that size(i.e. 1000) would do it and on each iteration, a variable of type integer would increase by 1 if the number generated is less than 5.
1
2
3
4
5
6
7
8
9
const int size=1000;
int counter=0;array[size];
for(int x=0;x<size;x++)
{
//y=your random number should be generated here.
// if y<5, increase the counter by 1, that is, counter+=1;
// array[x]=y;
}
//print out your counter 
Mar 14, 2013 at 1:58am
@Matri X - The problem statement doesn't indicate that an array is needed. Only the counter is needed.
Mar 14, 2013 at 2:01am
Right, so there's really no point in saving the values generated. Well he can ignore the array part of it
Topic archived. No new replies allowed.