필터 지우기
필터 지우기

write a program in matlab to calculate cmmmc in Matlab (do not use predefined function lcm)

조회 수: 4 (최근 30일)
o

답변 (1개)

Deepak
Deepak 2023년 7월 1일
Hey @ionita,
You can calculate cmmmc in MATLAB without using inbuilt LCM function with this method.
% Function to calculate the Greatest Common Divisor (GCD)
function gcd_val = gcd(a, b)
while b ~= 0
temp = b;
b = mod(a, b);
a = temp;
end
gcd_val = a;
end
% Function to calculate the CMMMC (Least Common Multiple)
function cmmmc_val = cmmmc(a, b)
cmmmc_val = abs(a * b) / gcd(a, b);
end
% Main program
num1 = input('Enter the first number: ');
num2 = input('Enter the second number: ');
cmmmc_result = cmmmc(num1, num2);
disp(['The CMMMC of ', num2str(num1), ' and ', num2str(num2), ' is ', num2str(cmmmc_result)]);

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by