2
$\begingroup$

Given

Table[n^i,{n,10},{i,10}]

what needs to be done so that the expression being evaluated "n^i=" will appear for every element. For instance for the 1st element it would be 1^1 =1 and for the last element it would be 10^10=100000000

$\endgroup$

2 Answers 2

3
$\begingroup$
Table[With[{i = i, n = n}, PromptForm[Defer[n^i], n^i]], {n, 5}, {i, 5}]
{{1^1 =  1, 1^2 =  1, 1^3 =  1, 1^4 =  1, 1^5 =  1}, 
 {2^1 =  2, 2^2 =  4, 2^3 =  8, 2^4 =  16, 2^5 =  32}, 
 {3^1 =  3, 3^2 =  9, 3^3 =  27, 3^4 =  81, 3^5 =  243},
 {4^1 =  4, 4^2 =  16, 4^3 =  64, 4^4 =  256, 4^5 =  1024}, 
 {5^1 =  5, 5^2 =  25, 5^3 =  125, 5^4 =  625, 5^5 =  3125}}
TableForm @ %

enter image description here

Note: PromptForm is still undocumented. It produces output similar to Row with separator " = ".

PromptForm[foo, bar]

enter image description here

Row[{foo, " = ", bar}]

enter image description here

Alternative methods:

TableForm @ Array[PromptForm[Defer[#^#2], #^#2] &, {5, 5}]

enter image description here

TableForm @ Outer[PromptForm[Defer[#^#2], #^#2] &, Range @ 5 , Range @ 5]

same picture

TableForm @ Array[Row[{Inactivate[Power @ ##], Power @ ##}, " = "] &, {5, 5}]

enter image description here

TableForm @ Outer[Row[{Inactivate[Power@##], Power@##}, " = "]&, Range @ 5, Range @ 5]

same picture

$\endgroup$
0
$\begingroup$

I would use Row:

Grid[
  Table[
    Row[{n, "^", i, " = ", n^i}]
  ,
    {n, 10}
  ,
    {i, 10}
  ]
,
  Alignment -> "=",
  Frame -> All,
  FrameStyle -> LightGray
]

Grid

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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