I am new on matla and this is my attempt on doing a code to get the GCD. Any tips?

이 topic에 Steven Lord 님이 플래그를 지정함
n= input('Escolhe um número inteiro postivo. ')
primo=true;
i=2;
while i<n
if mod(n,i)==0;
primo=false;
end
i= i+1;
end
if primo && n>1;
disp('É primo')
else
disp('Não é primo')
end
anterior= n-1;
while true
primo=true;
i=2;
while i< anterior
if mod(anterior,i)==0;
primo= false;
end
i= i+1;
end
if primo && anterior>1;
end
anterior= anterior-1;
end
disp(anterior)
seguinte= n+1;
while true;
primo= true;
i=2;
while i<seguinte;
if mod(seguinte,i)==0;
primo=false;
end
i=i+1;
end
if primo && seguinte>1;
end
seguinte= seguinte+1;
end
disp(seguinte)
Any ideas? It is in portuguese if you intend to translate it.
Stephen23
Stephen23 2026년 7월 8일
Steven Lord
Steven Lord 2026년 7월 6일
User posted this question again as https://www.mathworks.com/matlabcentral/discussions/general/888872-hello-guys-i-am-new-to-matlab-and-i-made-a-code-to-get-the-gcd-of-a-number-but-i-suspect-it-could-b and it looks like that got a comment with code. The two posts ought to be consolidated. Normally I'd say the newer post should be closed as a duplicate, but the comment in that newer post seems a bit more informative.
Duncan Carlsmith
Duncan Carlsmith 2026년 7월 4일
https://stackoverflow.com/questions/26753839/efficiently-getting-all-divisors-of-a-given-number

태그

아직 태그를 입력하지 않았습니다.