Find all numbers from 1 to 30 which are not multiples of 2 or 5 using Do,If,Mod,Print
What have you tried? It’s probably not in the cards to use this forum to have us do your homework for you ![]()
don’t know where to start
That’s a fair answer…!
First step is to read up in the documentation on Do, If, Mod, and Print and make sure you understand each.
Do will let you cycle through all of the numbers and do something for each of them.
If will let you test things and take an action if that test is True.
Mod will let you compute the remainder of a number when divided by another number.
Print will be the action you will take if the divisibility meets the requirements of the question that was posed.
Give it a try…
ok I understand what each of do,if,mod and print but im struggling to use them correctly this is what I have come up with so far
Print[Do[If {Mod[{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30}, 2,
5]}, n > 0, 0], {n, 30}]
Study the following code carefully don’t hand it in until you (a) understand each point and can explain why each piece does what it does and (b) in a separate notebook you can recreate it from scratch:
Do[
If[(Mod[n, 2] == 0) || (Mod[n, 5] == 0), Print[n]],
{n, 1, 30}
]