# Module that prints first m positive odd integers and returns the square root of the sum of them

I am working on this problem and I feel like I've come so close.

Write a module that takes as input a positive integer m, prints the first m positive odd numbers and returns the square root of the sum of the numbers it printed.

This is what I have so far:

kellyrocks[m_]:=Module[{index,sum},index=0;sum=0;

If[Or[m<= 0,IntegerQ[m]==False],Return["Please enter a positive integer"]];

While[index<=m,sum=sum+index;index=2*index+1];

Return[sqrt[sum]]]


But when I try to run it I'm not getting what I should, ex:

kellyrocks

sqrt


I'm very new to mathematica and I'm not sure what I'm missing. I also am not sure about printing each number. Thank you in advance!

• Welcome to Mathematica.SE! I suggest the following: 0) Browse the common pitfalls question 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Read the faq! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! – Dr. belisarius Mar 11 '16 at 3:45

g[n_Integer?(Positive@# &)] := (Print@#; Sqrt@Tr@#) &@Range[1, 2 n - 1, 2]

g

(*
{1,3,5}
3
*)

• The square root of 9 (1+3+5) is certainly not 35 – RunnyKine Mar 11 '16 at 2:47
• But, but, the square root of 9 is 3. It should be Sqrt@Tr@# – RunnyKine Mar 11 '16 at 2:50
• @RunnyKine Damn. You're too clever. Clearly an outlier :) – Dr. belisarius Mar 11 '16 at 2:51
• The answer is always going to be an integer, in fact, its always going to be n, so the N is probably not required. – RunnyKine Mar 11 '16 at 3:09
• @Kelly Oh, well. I disagree. You came here seeking for help and you should pay with the same coin you got. – Dr. belisarius Mar 11 '16 at 3:48