[gnome-university] c101: add some arithmetic information on chapter 2.



commit 31299b0585c5a794cb70f94959055892defc88ec
Author: Christian Hergert <christian hergert me>
Date:   Sun Nov 11 17:55:47 2012 -0800

    c101: add some arithmetic information on chapter 2.

 c101/tex/chapter2.tex |   32 +++++++++++++++++++++++++++++++-
 1 files changed, 31 insertions(+), 1 deletions(-)
---
diff --git a/c101/tex/chapter2.tex b/c101/tex/chapter2.tex
index b95c46b..95b46a0 100644
--- a/c101/tex/chapter2.tex
+++ b/c101/tex/chapter2.tex
@@ -9,6 +9,7 @@
     colorlinks,linkcolor=blue,citecolor=blue,
     urlcolor=red,
 ]{hyperref}
+\usepackage{amsmath}
 \usepackage{color}
 \usepackage{listings}
 \usepackage{parskip}
@@ -119,10 +120,39 @@ int b /* or the middle */ = 42;
 
 \section{Arithmetic}
 
+You do not need to be a math genius to be a competent C programmer.
+In fact, your author was never particularly great at math himself.
+Arithmetic works on variables and numbers similar to how you might have done basic algebra.
+You create a statement for which a result is calculated.
+In the following example multiply two numbers and assign the result to the variable \verb|x|.
+
+\begin{Terminal}
+int x = 10 * 20;
+\end{Terminal}
+
+This example assigns the value \verb|200| to the variable \verb|x|.
+It is important to note that we perform the operation (\verb|10 * 20|) on the right side of the assignment operator (\verb|=|) and assign that to the variable on the left side (\verb|x|).
+
+You need not specify \verb|int| every time you want to assign to the variable, just the first time when you declare it.
+For example, look at the following code.
+
+\begin{tabular}{l l}
+\verb|int x = 10 * 20;| & \verb|/*| $10 * 20 \Rightarrow 200 \Rightarrow x$ \verb|*/| \\
+\verb|x = x * 5;| & \verb|/*| $200 * 5 \Rightarrow 1000 \Rightarrow x$ \verb|*/| \\
+\end{tabular}
+
+On the first line we again assign \verb|200| to the variable \verb|x|.
+However, the second line looks a bit more tricky.
+We first perform the operation to the right of the assignment operator (\verb|=|) which is (\verb|x * 5|).
+Since \verb|x| is a variable we read the value of that variable.
+The value is \verb|200| which we calculated and assigned to \verb|x| on the first line.
+Then we multiply that by \verb|5| for a result of \verb|1000|.
+Finally, the value \verb|1000| is assigned to \verb|x|.
+
 TODO
 
 \begin{itemize}
-\item arithmetic and operators.
+\item arithmetic and operators and what they do.
 \item order of operations
 \end{itemize}
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]