finding divisibility in every number from 1 to 25

9 vues (au cours des 30 derniers jours)
karsten chan
karsten chan le 10 Sep 2021
Modifié(e) : Jan le 10 Sep 2021
hello,
i am trying to get a function that can find the divisiblity of 1 to 25 to 3 and 5
1 is NOT divisible by 3 or 5
2 is NOT divisible by 3 or 5
...
24 is divisible by 3
25 is divisible by 5
i havnt got any function done becuase i am bad at matlab, but i have an idea of using function and using loop to loop the divisibility of each number as they keep adding one from the last one

Réponses (1)

Jan
Jan le 10 Sep 2021
Modifié(e) : Jan le 10 Sep 2021
If x can by divided by y:
rem(x, y) == 0
Or:
x / y == round(x / y)
Another apporach is to calculate the list of multiples of 3:
m3 = 3:3:25
allNumbers = 1:25
Now ismember(allNumbers, m3) replies TRUE, if the number can be divided by 3.

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