you have a sequence where each number is a multiple of 2 or 5 (so: 2^i * 5^j). Given the beginning of the sequence as 1,2,4,5,8,10,16... and find a algorithm to calculate the next number in the sequence?
Answer:
This answer gives u the pattern to make the sequence. Algorithm would look like this.
1. Make set1 with all powers of 2(i.e 2,4,8,...)
2. Make set2 with all powers of 5(i.e 5,25,125 ...)
3. Make set3 with product of numbers from set1 and set2(i.e 10,20,40,50,80,100 etc..)
Make sure that third set is sorted.
Now display elements from set1 till u find a element less than starting element in set2 or set3. Otherwise display minimum element out of elements from set2 or set3.
Categories
FollowersBlog Archive
Jobs
Find more freelance jobs
|
Sunday, March 21, 2010
Subscribe to:
Post Comments (Atom)
|
Popular Posts
|
No comments:
Post a Comment