# How can I get an array of numbers from the user and show the numbers with formatting?

Suppose that I have to print the following lines:

Number 1 is 5 Number 2 is 6 Number 3 is 7 Number 4 is 8 Number 5 is 9

Now, if I were programming in C, I would have run the following code :

for(i=1;i<=5;i++)
{printf("Number %d is %d \n",i,i+4);}


Print["Number %d is %d", i, i + 4] doesn't work in Mathematica (and yes, I am aware of it).

Moreover, in $C$, I can scan input like this:

for(i=0;i<5;i++)
{printf("Enter Number %d: ",i);
scanf("%d",&Scanned[i])};           \* Where Scanned[i] is the Array Storing Values of the Numbers *\


I tried

For[i = 0, i < 5, i++, Scanned[i] = Input["Enter the Number %d: ", i]]


But it didn't work (I guess %d is not recognizable by Mathematica).

So how would I implements these tasks in Mathematica?

(I apologize if this question is of very low level, but I searched a lot for it, and didn't get an appropriate answer to my query.)

• Take a look at StringTemplate or StringForm to learn about templates syntac in Mathematica. The way to go is Do + Print + StringTemplate. You may also be interested in column. – Kuba Jun 17 '17 at 16:38
• See also: 11305 – Kuba Jun 17 '17 at 16:41
• I would add see this on avoiding for loops--just generally good knowledge for people new to Mathematica. – b3m2a1 Jun 17 '17 at 16:54

## 1 Answer

StringForm["Number  is ", #, # + 4] & /@ Range[5] // Column


Print[StringForm["Number  is ", #, # + 4]] & /@ Range[5];


n = 1; While[n < 6,
Print[StringForm["Number  is ", n,
InputString["Enter number " <> ToString[n++]]]]]