필터 지우기
필터 지우기

How do I find all odd numbers between 1 and 60 but are divisible by 5?

조회 수: 4 (최근 30일)
Samariah
Samariah 2023년 10월 21일
편집: Torsten 2023년 10월 21일
How do I find all odd numbers between 1 and 60 but are divisible by 5 using the for loop?
  댓글 수: 12
Samariah
Samariah 2023년 10월 21일
mod(60, 5) this gave me 0 but how to I incorporate this into my for loop?
Torsten
Torsten 2023년 10월 21일
편집: Torsten 2023년 10월 21일
This is almost a solution. More hints are not possible.
for i = 1:60
if mod(...) == 1 && mod(...) == 0
disp(i)
end
end
or shorter
X = 1:60;
X = X(mod(...) == 1 & mod(...) == 0)

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
Walter Roberson 2023년 10월 21일
hint:
for i = 1 : 60
r7 = remainder7(i);
if r7 == 0; disp(i); end
end
7 14 21 28 35 42 49 56
function v = remainder7(v)
while v >= 7
v = v - 7;
end
end

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by