Message Boards Message Boards

0
|
2748 Views
|
5 Replies
|
0 Total Likes
View groups...
Share
Share this post:

using Do,If,ModPprint

Posted 10 years ago

Find all numbers from 1 to 30 which are not multiples of 2 or 5 using Do,If,Mod,Print

POSTED BY: sam adams
5 Replies

What have you tried? It's probably not in the cards to use this forum to have us do your homework for you ;-)

POSTED BY: David Reiss
Posted 10 years ago

don't know where to start

POSTED BY: sam adams

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...

POSTED BY: David Reiss
Posted 10 years ago

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}]

POSTED BY: sam adams

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}
 ]
POSTED BY: David Reiss
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract