# Integer arithmetic in TeX

After many years of being merely a regular TeX (LaTeX lately) I started reading little bit more recently. I wrote a small program (very naive) which is suppose to illustrate doing integer arithmetic in TeX.

\message{Please enter the first number:}

The first entered number is \first

\count0=\first

\count1=\second

The second entered number is \second

Could you please compare the sum of number you have entered and
the number of the page :)
\bye


Is there a simple way to recover the content of register \count0 on an arbitrary place on the page?

-
You find the total at the bottom of the page, as Plain TeX uses \count0 for assigning the value to the page number. :) –  egreg Dec 27 '11 at 11:11
I think you have not read my example carefully :) –  Predrag Punosevac Dec 27 '11 at 13:40
Just a joke to advise you about being careful in not using \count0 outside of a group. ;-) –  egreg Dec 27 '11 at 13:43
I apologize for being a slow student :) I promise I will try to read comments more carefully and try to think before I replay :) –  Predrag Punosevac Dec 27 '11 at 14:25

In order to obtain \count0, use \the\count0. This will typeset the value of \count0 wherever it is used.

\message{Please enter the first number:}

The first entered number is \first

\count0=\first

\count1=\second

The second entered number is \second

Could you please compare the sum of number you have entered and
the number of the page :) \the\count0
\bye

-

To complete the answer of Werner :

You can also use \number. If \count213=1789 then \the\count213and \number\count213 are equivalent, but if you can write \number2012 it's not possible to write \the2012 or \the{2012} .

If you want to learn something about integers with TeX, you can look at the sources of the TeXBook, for example Knuth writes this code :

\newif\ifprime \newif\ifunknown
\newcount\n \newcount\p \newcount\d \newcount\a
\def\primes#1{2,~3% assume that #1 is at least 3
\n=#1 \advance\n by-2 % n more to go
\p=5 % odd primes starting with p
\def\printp{, % we will invoke \printp if p is prime
\ifnum\n=1 and~\fi % this precedes the last value

In this code Knuth uses \number\p.