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:


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



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



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!

  • $\begingroup$ 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! $\endgroup$ – Dr. belisarius Mar 11 '16 at 3:45
g[n_Integer?(Positive@# &)] := (Print@#; Sqrt@Tr@#) &@Range[1, 2 n - 1, 2]


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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.