0

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.)

David G. Stork
  • 41,180
  • 3
  • 34
  • 96
Raj
  • 11
  • 1

1 Answers1

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

enter image description here

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

enter image description here

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

enter image description here

Bob Hanlon
  • 157,611
  • 7
  • 77
  • 198