Yashraj Jadhao
New Member
- Joined
- Nov 14, 2021
- Messages
- 9
- Office Version
- 2021
- Platform
- MacOS
Place a button labelled “Prime or Not Prime” into a spreadsheet that when pressed executes a macro
named PrimeorNot that asks the user to type in a number using the InputBox() function, it then uses
a loop structure to attempt to divide the number with integer numbers beginning with 2 and going up
by one unit at a time (e.g. it attempts to divide by 2, then 3, then 4, etc.). Your macro should check
when the user types in their number to make sure it is a number greater than zero and that it is an
integer (note, prime numbers are typically defined as numbers that are positive), and if it is not then
they should tll the user “Your number was not a positive integer. You must reselect a positive integer
to test for being prime.” and then have them input another number using the InputBox function. (Note:
A WHILE loop can be used to do this type of input, test, and repeat function very efficiently). If the
macro finds that any number divides evenly into the user’s number then have it print a message to the
user using the MsgBox() function that states “Your number is not prime”. If it finds that no number
divides evenly into the number divides then have it return a message to the user using the MsgBox()
function that states “Your number is prime.” NOTE: You can stop and report a number is not prime if
any number divides evenly into it. You also only need to test up to numbers equal to ½ the user
number (you can think about why).
named PrimeorNot that asks the user to type in a number using the InputBox() function, it then uses
a loop structure to attempt to divide the number with integer numbers beginning with 2 and going up
by one unit at a time (e.g. it attempts to divide by 2, then 3, then 4, etc.). Your macro should check
when the user types in their number to make sure it is a number greater than zero and that it is an
integer (note, prime numbers are typically defined as numbers that are positive), and if it is not then
they should tll the user “Your number was not a positive integer. You must reselect a positive integer
to test for being prime.” and then have them input another number using the InputBox function. (Note:
A WHILE loop can be used to do this type of input, test, and repeat function very efficiently). If the
macro finds that any number divides evenly into the user’s number then have it print a message to the
user using the MsgBox() function that states “Your number is not prime”. If it finds that no number
divides evenly into the number divides then have it return a message to the user using the MsgBox()
function that states “Your number is prime.” NOTE: You can stop and report a number is not prime if
any number divides evenly into it. You also only need to test up to numbers equal to ½ the user
number (you can think about why).