|
-
January 22nd, 2003, 10:25 PM
#1
Print a random number from set
For each of the following sets of integers, write a single
statement that will print a number at random from the set.
c) 6,10,14,18,22
I can't do this in one line. the best i can do is:
num = 1;
while((num % 4) || (num > 24)) num = rand() % 24 + 8;
num -= 2;
cout << "Number in set {6,10,14,18,22}: " << num << endl;
return 0;
Any thoughts?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|