老师布置的作业,不会啊 求助。

3 visualizaciones (últimos 30 días)
dewavo laeaesr
dewavo laeaesr el 28 de Oct. de 2022
Respondida: litaeva el 28 de Oct. de 2022
编写函数文件ex4_1.m用于求两个正整数的最大公约数(不可调用函数gcd)。再编写测试脚本ex4_11.m调用ex4_1输出从键盘输入的两个正整数的最大公约数和最小公倍数

Respuesta aceptada

litaeva
litaeva el 28 de Oct. de 2022
function gcd=mygcd(m,n)
    while(m~=n)
       if(m>n)   
           m=m-n;   
       else   
            n=n-m;
        end
     end
   gcd=n;
end
调用
56*24/mygcd(56,24)

Más respuestas (0)

Categorías

Más información sobre Downloads en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!