solise3
(Erly Solis)
March 13, 2015, 4:38am
1
This is PROBLEM I HAVE TO DO.
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.
mthiel
(Marco Thiel)
March 13, 2015, 3:35pm
2
Hi,
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}]]]]}, "."}]]
Cheers,
M.
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:
http://community.wolfram.com/guidelines
If you see inappropriate discussions please do not respond in future but let moderators know by flagging the post or emailing at:
wolfram-community@wolfram.com
Thank you for your patience and understanding!
Sincerely,
Moderation Team