Question: my code looks like this so far: clear; clc; A=input('Enter the first number: '); B=input('Enter the second number: '); result=1; i=1; while (i if (mod(A,i)==0&&mod(B,i)==0)

my code looks like this so far:
clear; clc;
A=input('Enter the first number: ');
B=input('Enter the second number: ');
result=1;
i=1;
while (i
if (mod(A,i)==0&&mod(B,i)==0)
result=i;
end
i=i+1;
end
fprintf('The LCM of %d and %d is %d!',A,B,(A*B)/result);
However, when I try the 6 and 8 test it gives me 48 instead of 24 and I don't understand why. It works for the other Tests. Please help so it works for all of the Test Cases.
Thanks!
Question 1. Given two positive numbers, write a program using while loop to determine their lowest common multiple. You cannot use any automatic LCM, GCD finder function or return command. Program Inputs Enter the first number: - The user can enter any positive whole number, no error checking required Enter the second number: - The user can enter any positive whole number, no error checking required Program Outputs The LCM of X and Y is Z! Replace X with first number, Y with second number and Z with LCM. Test Case 1: Enter the first number: 2 Enter the second number: 7 The LCM of 2 and 7 is 14! Test Case 2: Enter the first number: 12 Enter the second number: 13 The LCM of 12 and 13 is 156! Test Case 3: Enter the first number: 6 Enter the second number: 8 The LCM of 6 and 8 is 24! Test Case 4: Enter the first number: 25 Enter the second number: 26 The LCM of 25 and 26 is 650! Test Case 5: Enter the first number: 17 Enter the second number: 47 The LCM of 17 and 47 is 799
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
