Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

randomized

Posted on 1999-01-08
11
Medium Priority
?
299 Views
Last Modified: 2010-04-15
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
Comment
Question by:samuelccs
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
  • +3
11 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 1255640
Is this a homework assignment?
0
 
LVL 5

Expert Comment

by:scrapdog
ID: 1255641
Post the code you have so far.
0
 

Expert Comment

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

Have fun folks!
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Expert Comment

by:rsongyl
ID: 1255643
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
 
LVL 5

Expert Comment

by:scrapdog
ID: 1255644
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
 

Accepted Solution

by:
tato earned 60 total points
ID: 1255645

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

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

0
 
LVL 5

Expert Comment

by:scrapdog
ID: 1255646
Tato:  please do not post as an answer something somebody else already posted as a comment.
0
 
LVL 84

Expert Comment

by:ozo
ID: 1255647
especially when it's incorrect
0
 
LVL 5

Expert Comment

by:scrapdog
ID: 1255648
I know that my code did not meet samuelccs's specifications *exactly*...my intention was for a general "hint".
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1255649
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
 
LVL 10

Expert Comment

by:viktornet
ID: 1255650
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
Suggested Courses

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question