VISUAL BASIC 2012 Write a program that generates random numbers while the cube o
ID: 3773509 • Letter: V
Question
VISUAL BASIC 2012
Write a program that generates random numbers while the cube of the current random number is greater than the sum of the previously generated random numbers. E.g.
2, 8, 0 - first number is 2, its cube is 8, the sum of the previous number is 0
5, 125, 2 - second number is 5, its cube is 125, the sum of the previous numbers is 2
3, 27, 7 - third number is 3, its cube is 27, the sum of the previous numbers is 2 + 5 = 7
6, 216, 10 - fourth number is 6, its cube is 216, the sum of the previous numbers is 2 + 5 + 3 = 10
Explanation / Answer
This is Code for above given problem is :
Function fnRandomNumber(LengthOfRandomNumber)
Dim sMaxVal : sMaxVal = ""
Dim iLength : iLength = LengthOfRandomNumber
'Find the maximum value for the given number of digits
For iL = 1 to iLength
sMaxVal = sMaxVal & "9"
Next
sMaxVal = Int(sMaxVal)
'Find Random Value
Randomize
iTmp = Int((sMaxVal * Rnd) + 1)
'Add Trailing Zeros if required
iLen = Len(iTmp)
fnRandomNumber = iTmp * (10 ^(iLength - iLen))
End Function
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.