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

An Armstrong number is an integer such that the sum of the cubes of its digits...
An Armstrong number is an integer such that the sum of the cubes of its digits is equal to the number itself. For example, 371 is an Armstrong number since 3**3 + 7**3 + 1**3 = 371. Write a C function to print all Armstrong numbers between a given interval. Then write a C program to keep reading two integers and print all Armstrong numbers between these two integers by calling that function.
Write a PL/SQL program that prints following: if sum of its digits raised to the power...
Write a PL/SQL program that prints following: if sum of its digits raised to the power n is equal to number itself, where n is total digits in number. If the Input is: 129, then output of the program will be: 738
Directions: Given a factorial n!. Find the sum of its digits, and the number of trailing...
Directions: Given a factorial n!. Find the sum of its digits, and the number of trailing zeros (ie: the number of zeros at the end of the factorial). Input: integer n , a non-negative integer where n ≤ 100 Output: integer x y , the concatenation of x and y, where x is the sum of the digits in n! and y is the number of the zeros in n!) Note, 0 ≤ x , y . Example: Consider the...
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...
A palindromic number is a number that remains the same when its digits are reversed. For...
A palindromic number is a number that remains the same when its digits are reversed. For examples, 1, 11, 99, 121 are palindromic. Write a program that takes one array of 10 positive integers as input and output all the palindromic numbers in this array. We assume that each input number is valid, i.e., a positive integer. Hint: You can consider the following steps to check whether a number (e.g., 121) is palindromic • Store this number to one variable,...
19. Under sum-of-the-years’-digits depreciation . . . a. the book value remains the same each year....
19. Under sum-of-the-years’-digits depreciation . . . a. the book value remains the same each year. b. the depreciation rate changes each year. c. the denominator of the SYD fraction changes each year. d. all of the above. 20. For assets acquired during the year, the sum-of-the-years’-digits method requires that the same depreciation rate be used . . . a. for the remaining months of the year of acquisition, then again in the final year of the asset’s estimated life...
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....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT