Question

In: Computer Science

An Armstrong number is a number that is the sum of its own digits, each raised...

An Armstrong number is a number that is the sum of its own digits, each raised to the power of the number of its digits. For example, 153 is considered an Armstrong number because 13 + 53 + 33 = 153.

Write a VBA program that lists all 3-digit Armstrong numbers within a specified range of 3-digit positive integers. Your sub should do the following: 1) Using two input boxes, ask the user to input two 3-digit positive integers (a "lower bound" and an "upper bound" for the range); 2) Enter all Armstrong numbers between the specified numbers in column A, staring with cell A1. Hints: Use a For Loop. Also, string functions can be used on LONG variables.

Solutions

Expert Solution

VBA Code:

Function generateArmstringNumber()

'variable for upperbound lowerbound
Dim upperBound, lowerBound As Integer
Dim armStrongNumbers As New Collection 'to store the list of armstrong numbers
'getting the data from the user
lowerBound = CInt(InputBox("Enter lower bound(3- Digit Number)"))
upperBound = CInt(InputBox("Enter upper bound(3- Digit Number)"))
'declaring program variables
Dim i As Integer
Dim itemp As Integer
Dim units, tens, hundreds As Integer
Dim sumOfDigits As Integer
'looping from lowerbound to upperbound
For i = lowerBound To upperBound
itemp = i 'taking a temporary value of i
'getting each digit
units = itemp Mod 10
itemp = itemp \ 10
tens = itemp Mod 10
itemp = itemp \ 10
hundreds = itemp Mod 10
'calculating sum of digits
sumOfDigits = units ^ 3 + tens ^ 3 + hundreds ^ 3
'checking if sum of digits equals i
If sumOfDigits = i Then
armStrongNumbers.Add (i) 'if so adding to the list
End If
Next i

Sheets("Sheet1").Cells.Clear 'clearing existing data
'displaying the list in the column 1
For i = 1 To armStrongNumbers.Count
Cells(i, 1) = armStrongNumbers.Item(i)
Next i

End Function

Sample Output:

153
370
371
407

lowerbound = 100

upperbound = 999


Related Solutions

Determine a two digit number whose value is equal to eight times the sum of its digits and when 45 is subracted from the number, the digits are reversed?
Determine a two digit number whose value is equal to eight times the sum of its digits and when 45 is subracted from the number, the digits are reversed?
In a two digit number the sum of the digits is 9. Also, when 27 is subtracted from the number the digits are reversed. Find the number?
In a two digit number the sum of the digits is 9. Also, when 27 is subtracted from the number the digits are reversed. Find the number?
A visible-factor number is a natural number that is divisible by each of its nonzero digits,...
A visible-factor number is a natural number that is divisible by each of its nonzero digits, for example, 424 or 505. How many visible-factor numbers are less than 100?
A random number X is generated by reporting the sum of the digits on two randomly...
A random number X is generated by reporting the sum of the digits on two randomly chosen ping-pong balls, one from a bucket of two balls labeled “0” and “1” and one from a bucket of three balls labeled “0”, “1”, and “2”. Find the probability mass function of X by specifiying the values x that X can take and the probability p(x) = P (X = x) of each of those values. Please explain how you arrived at the...
Write an Assembley Language.Given a number x, determine whether the given number is Armstrong number or...
Write an Assembley Language.Given a number x, determine whether the given number is Armstrong number or not. A positive integer of n digits is called an Armstrong number of order n(where order is the number of digits) if.    abcd... = pow(a,n) + pow(b,n) + pow(c,n) + pow(d,n) + .... Example: Input : 153 Output : Yes, 153 is an Armstrong number. 1*1*1 + 5*5*5 + 3*3*3 = 153 Input : 120 Output : No, 120 is not a Armstrong number....
On October 18, 2017, Armstrong Auto Corporation ("Armstrong") announced its plan to acquire 80 percent of...
On October 18, 2017, Armstrong Auto Corporation ("Armstrong") announced its plan to acquire 80 percent of the outstanding 500,000 shares of Bardeen Electric Corporation’s ("Bardeen") common stock in a business combination following regulatory approval. Armstrong will account for the transaction in accordance with ASC 805, “Business Combinations.” On December 1, 2017, Armstrong purchased an 80 percent controlling interest in Bardeen’s outstanding voting shares. On this date, Armstrong paid $40 million in cash and issued one million shares of Armstrong common...
Question 3: Sum-of-digit method The sum of years' digits method is a form of accelerated depreciation...
Question 3: Sum-of-digit method The sum of years' digits method is a form of accelerated depreciation that is based on the assumption that the productivity of the asset decreases with the passage of time. Under this method, a fraction is computed by dividing the remaining useful life of the asset on a particular date by the sum of the year's digits. Problem Snitcher Corp. purchases a property for $100,000. It has an estimated salvage value of $10,000, and a useful...
Let A be the sum of the last four digits and let B be the last...
Let A be the sum of the last four digits and let B be the last digit of your 8-digit student ID. (Example: For 20245347, A = 19 and B = 7) On a road trip, a driver achieved an average speed of (48.0+A) km/h for the first 86.0 km and an average speed of (43.0-B) km/h for the remaining 54.0 km. What was her average speed (in km/h) for the entire trip? Round your final answer to three significant...
Find the number of passwords that use each of the digits 3,4,5,6,7,8,9 exactly once. IN how...
Find the number of passwords that use each of the digits 3,4,5,6,7,8,9 exactly once. IN how many of the passwords: 1. are the four odd digits consecutive? 2. are no two odd digits consecutive? 3. are the first three digits even? 4. are the three even digits consecutive?
During 2019 and 2020, Faulkner Manufacturing used the sum-of-the-years’-digits (SYD) method of depreciation for its depreciable...
During 2019 and 2020, Faulkner Manufacturing used the sum-of-the-years’-digits (SYD) method of depreciation for its depreciable assets, for both financial reporting and tax purposes. At the beginning of 2021, Faulkner decided to change to the straight-line method for both financial reporting and tax purposes. A tax rate of 25% is in effect for all years. For an asset that cost $21,000 with an estimated residual value of $1,000 and an estimated useful life of 10 years, the depreciation under different...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT