• Status: Solved
• Priority: Medium
• Security: Public
• Views: 301

# randomized

generate 100 unique (just one time only) integer random numbers between 1000 and 10000 in an array rn[100]. How many of these numbers fall between 4000 and 7000?
0
samuelccs
• 4
• 2
• 2
• +3
1 Solution

Commented:
Is this a homework assignment?
0

Commented:
Post the code you have so far.
0

Commented:
Since I am the one who set this question in class I will be very interested to see the answer.

Have fun folks!
0

Commented:
Can be done easily. You want the short way or the long way?
The long way is set all the number with counters and if anything hits 2, reset it.
The short way?? Press F1 if you need help. I think they have online help services.

0

Commented:
Well, now that you're already in trouble with your teacher, it couldn't get any worse!!

for(i=0;i<9000;i++) x[i]=i+1000;
for(i=0;i<100;i++) { r=random(9000); t=x[i]; x[i]=x[r]; x[r]=t; }
for(i=0;i<100;i++) { if((x[i]>=4000)&&(x[i]<=7000)) n++; }
0

Commented:

for(between=i=0;i<100;i++) if (array[i]>=4000 & array <=7000) between++;

printf("between 4000 and 7000 = %d",between);

0

Commented:
0

Commented:
especially when it's incorrect
0

Commented:
I know that my code did not meet samuelccs's specifications *exactly*...my intention was for a general "hint".
0

Commented:
OK, guys, here is my code... Maybe not the best, but who cares....

#include <iostream.h>
#include <conio.h>
#include <stdlib.h>

int main()
{
int array[100];
int ran, n = 0;
bool dup;

randomize();
for (int i = 0; i < 100; i++) {
dup = FALSE;
ran = random(9000) + 1001;
for (int j = 0; j <= i; j++) {
if (array[j] == ran)
dup = TRUE;
}
if (!dup) {
array[i] = ran;
cout << array[i] << ' ';
if (array[i] >= 4000 && array[i] <= 7000) n++;
} else i--;
}
cout << "\n\nThere were " << n << " in the range of 4000 and 7000";
return 0;
}
0

Commented:
Oppps....

THis line

cout << "\n\nThere were " << n << " in the range of 4000 and 7000";

should have been

cout << "\n\nThere were " << n << " numbers in the range of 4000 and 7000";
0

## Featured Post

• 4
• 2
• 2
• +3
Tackle projects and never again get stuck behind a technical roadblock.