0
$\begingroup$

Suppose I have:

Do[Print[i/i!], {i, 1, 10}]

I would like the output to be like:

1/1!, 2/2!, 3/3! , ...,10/10!

However, when I use the code above the factorial evaluates by Mathematica. I tried to enclose the factorial part by TraditionalForm or Unevaluated but it didn't help.

How can I get the form I like as above?

$\endgroup$
  • 3
    $\begingroup$ There are many similar questions. Search for HoldForm: #/HoldForm[#!] & /@ Range[10] $\endgroup$ – Kuba Jan 29 '15 at 13:21
  • $\begingroup$ It seems inside a loop HoldForm doesn't work. $\endgroup$ – MOON Jan 29 '15 at 13:27
  • 1
    $\begingroup$ Use With to inject i. Or Inactivate[Factorial][i] or #/HoldForm[#!] &[i] inside the loop.; $\endgroup$ – Kuba Jan 29 '15 at 13:29
3
$\begingroup$

Utilizing the suggestion of @Kuba With:)

Like this:

Do[
 Print[
   With[{j = i}, HoldForm[j/j!]]], {i, 1, 10}]

Or

Table[
  With[{j = i}, HoldForm[j/j!]], {i, 1, 10}]

$\left\{\frac{1}{1!},\frac{2}{2!},\frac{3}{3!},\frac{4}{4!},\frac{5}{5!},\frac{6}{6!},\frac{7}{7!},\frac{8}{8!},\frac{9}{9!},\frac{10}{10!}\right\}$

$\endgroup$

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.