Effacer les filtres
Effacer les filtres

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

4 vues (au cours des 30 derniers jours)
Samariah
Samariah le 21 Oct 2023
Modifié(e) : Torsten le 21 Oct 2023
How do I find all odd numbers between 1 and 60 but are divisible by 5 using the for loop?
  12 commentaires
Samariah
Samariah le 21 Oct 2023
mod(60, 5) this gave me 0 but how to I incorporate this into my for loop?
Torsten
Torsten le 21 Oct 2023
Modifié(e) : Torsten le 21 Oct 2023
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)

Connectez-vous pour commenter.

Réponses (1)

Walter Roberson
Walter Roberson le 21 Oct 2023
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

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by