Click here to Skip to main content
15,886,052 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
i have a problem, you know the way you write a loop that output a number from 1 to 10. except this time how do i put the set of numbers like 23 23 24 65 3 556 44 65 43....... inside a code so that that my output would give me what i want. i don't wanna do it through array is there any other way? pls help. thanks
Posted
Comments
ZurdoDev 18-Aug-15 15:17pm    
Why don't you want to use an array? A loop is not the right method.
gipsy danger 18-Aug-15 15:22pm    
i wanna write a code that reads over 300 numbers in the code and outputs the biggest nunber
Sergey Alexandrovich Kryukov 18-Aug-15 17:41pm    
What have you tried so far?
—SA

If you have to iterate over a predefined set of numbers, written in the code, then you have no choice: you have to use a container (like the proposed array) to store them.
An alternative would be reading them from the user (or from an input file) and processing them incrementally (albeit, again, storing the read numbers in ant array would be an effective way to handle the problem).
Another alternative, if fits your needs, would be using the random number generator to get a fresh number at each iteration.
 
Share this answer
 
I'll take this crazy mixed up challenge.

JavaScript follows, because everybody got JS.

var numberSet = [ 23, 23, 24, 65, 3, 556, 44, 65, 43];
var randomIdx = (Math.floor(Math.random()*numberSet.length));
// run this 100 times just to see what values you get
for (x = 0;x < 100;x++)
{
  console.log(numberSet[randomIdx]);
  randomIdx = (Math.floor(Math.random()*numberSet.length));
}



Now you can change numberSet to be any set of numbers you want by simply typing in values with followed by a comma. The length of the set is used in the random generator to determine which indice of the numberSet it should print on the console.

Note: use F12 to show the console.
Note: Vote this answer UP gratuitously, because it are gen1us.

EDIT: I created a plunker for this: it pretty cool cuz you can see the values on the screen.
Check it out at: http://plnkr.co/edit/B7H3PDCcVhPs1Dt2L2aZ?p=preview[^]

Looks like: top part is value, bottom part is indice used
24   556   556   65   44   43   24   44   44   65   3   44   44   3   3   65   43   65   23   43   65   556   44   3   23   65   23   43   23   24   65   44   23   556   23   43   65   24   44   44   3   3   43   43   23   43   23   23   43   556   65   556   65   3   3   65   24   556   24   556   24   556   65   65   24   23   65   556   44   43   65   23   24   23   3   23   23   65   24   65   44   3   24   65   23   65   3   65   3   23   23   24   65   23   556   23   65   65   65   43   
#########################

5   5   7   6   8   2   6   6   7   4   6   6   4   4   3   8   7   0   8   7   5   6   4   1   7   0   8   0   2   7   6   1   5   0   8   7   2   6   6   4   4   8   8   0   8   0   0   8   5   3   5   7   4   4   3   2   5   2   5   2   5   7   7   2   0   7   5   6   8   3   0   2   0   4   0   0   3   2   7   6   4   2   7   0   3   4   7   4   1   1   2   7   1   5   1   7   7   3   8   6 
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900