1
$\begingroup$

I want to generate a table of roots and perfect squares similar to the image, but I can't find the right code, I have searched the forum for something that works for me without favorable results. Can someone help me?

enter image description here

Print["Cuadrados de los números hasta 100"]
Print["================================="]


columnas = 10;
rango = Range[100];
cuadrados = Map[#^2 &, rango];
grupos = Partition[cuadrados, columnas];


Map[Print[StringForm["``^2 = ``", #[[1]], #[[2]]]] &, Transpose[{rango, cuadrados}]];
$\endgroup$

1 Answer 1

7
$\begingroup$
$Version

(* "13.2.1 for Mac OS X ARM (64-bit) (January 27, 2023)" *)

Clear["Global`*"]

nmax = 100;

Row[
 Grid[#, Frame -> All] & /@
  Partition[
   Table[
    {
     StringForm["``=``", ToString[n]^2, n^2],
     StringForm["``=``", Sqrt[ToString[n^2]], n]},
    {n, nmax}],
   25]]

enter image description here

$\endgroup$
3
  • 1
    $\begingroup$ ,wow ,it was easy, but what broke my head and you wrote it in one fell swoop, thanks $\endgroup$
    – zeros
    May 20 at 3:11
  • $\begingroup$ Quick question to @BobHanlon: Why must the order be StringForm["``=``", ToString[n]^2, n^2] when it would seem it should be instead StringForm[ToString[n]^2, "``=``", n^2]? $\endgroup$ May 20 at 17:14
  • 1
    $\begingroup$ @DavidG.Stork - See the documentation. The first argument to StringForm is the "controlstring` (i.e., template) to be filled by the subsequent arguments. $\endgroup$
    – Bob Hanlon
    May 20 at 17:43

Your Answer

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

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