Message Boards Message Boards


HELP with Mathematica Homework

Posted 8 years ago
2 Replies
0 Total Likes


Write a module that takes as input a positive integer m prints the first m positive odd numbers and returns the sum of the numbers it printed. You should use the Print command in the module. Look it up in the Wolfram Documentation center available under the Help tab. Run this module for 3 different numbers between 20 and 50.

POSTED BY: Erly Solis
2 Replies

Wolfram Community is only for the discussions of Wolfram Technologies.

Other unrelated topics (for example, obvious homework requests, or purely scientific topics) should be posted on different, appropriate forums.

We are very grateful to all contributors offering help and contributing to Community.

But unfortunately we cannot support discussions outside Community guidelines:

If you see inappropriate discussions please do not respond in future but let moderators know by flagging the post or emailing at:

Thank you for your patience and understanding!

Sincerely, Moderation Team

POSTED BY: Moderation Team


sounds like homework. This should work:

f[m_Integer] := Module[{k = m}, Table[Print[2 (j - 1) + 1], {j, 1, k}]; 
  StringJoin[{{"The sum is ", ToString[Evaluate[Total[Table[2 (j - 1) + 1, {j, 1, k}]]]]}, "."}]]

You can easily evaluate that for three different numbers.

The print command is somewhat artificial, because table does it anyway. But here is a variant where the Print is important:

g[m_Integer] := Module[{k = m}, For[j = 1, j <= k, j++, Print[2 (j - 1) + 1]]; 
  StringJoin[{{"The sum is ", ToString[Evaluate[Total[Table[2 (j - 1) + 1, {j, 1, k}]]]]}, "."}]]



POSTED BY: Marco Thiel

Group Abstract Group Abstract