# [Tex/LaTex] How to calculate n modulo 3 in LaTeX

calculations

I don't want to display the modulo symbol, I want to programmatically calculate n modulo 3 and display the result.

You can also use \intcalcMod from the intcalc package:

\documentclass{article}
\usepackage{amsmath}
\usepackage{ifthen}
\usepackage{intcalc}

\newcounter{mycount}
\newcommand\Nmodiii[1]{%
\setcounter{mycount}{0}\whiledo{\value{mycount}<#1}
{$\themycount\pmod 3=\intcalcMod{\value{mycount}}{3}$\\\stepcounter{mycount}}
}
\begin{document}

\noindent A little example: $8\pmod 3=\intcalcMod{8}{3}$

\noindent And a little loop:\\
\Nmodiii{20}

\end{document}


The code that appears in the link posted in a comment, there are some spurious blank spaces producing an undesired indentation of the first line; here's a corrected version:

\documentclass{article}
\usepackage{ifthen}
\usepackage{forloop}
\usepackage{fmtcount}
\usepackage{intcalc}
\usepackage{multicol}

\begin{document}
\begin{multicols}{2}
\newcounter{i}
\noindent\forloop{i}{1}{\value{i} < 101}{%
\ifthenelse{\equal{\intcalcMod{\value{i}}{15}}{0}}{
FizzBuzz
}{%
\ifthenelse{\equal{\intcalcMod{\value{i}}{3}}{0}}{
Fizz
}{%
\ifthenelse{\equal{\intcalcMod{\value{i}}{5}}{0}}{
Buzz
}{%
\thei
}
}
}\\
}
\end{multicols}
\end{document}