Question: Create an HLA function that checks whether a desired value happens to be a factor of another number. For example, the factors of the number
Create an HLA function that checks whether a desired value happens to be a factor of another number. For example, the factors of the number 12 happen to be 1, 12, 3, 4, 2 and 6 because 1 * 12 = 12, 3 * 4 = 12 and 2 * 6 = 12.
This function should have the following signature: procedure isFactor( value : int16; desiredFactor : int16 );@nodisplay; @noframe; This function should return a boolean value of true if the desiredFactor parameter is a factor of the value parameter. Your function should replicate the following C code: bool isFactor( int value, int desiredFactor ) {
bool result = false;
if (desiredFactor > 0) { while (value > 0) {
value = value - factor; // eventually we will hit 0 or a negative number... }
// if we hit zero, then the desiredFactor really is a factor of value!
if (value == 0) result = true;
}
return( result );
} IN ORDER TO RECEIVE FULL CREDIT, YOU CANNOT USE MULTIPLY OR DIVIDE INSTRUCTIONS. Instead, please loop as shown above.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
