[gnome-university] Add basic arithmetic example.



commit 5afaf1f57e1be0c6325763366aecb42e729a3daf
Author: Christian Hergert <christian hergert me>
Date:   Sun Nov 4 17:13:36 2012 -0800

    Add basic arithmetic example.

 c101/tex/chapter2.tex |   26 ++++++++++++++++++++++++++
 1 files changed, 26 insertions(+), 0 deletions(-)
---
diff --git a/c101/tex/chapter2.tex b/c101/tex/chapter2.tex
index 94891a8..933f0d3 100644
--- a/c101/tex/chapter2.tex
+++ b/c101/tex/chapter2.tex
@@ -87,6 +87,32 @@ int b /* or in between */ = 42;
 
 \section{Arithmetic}
 
+\begin{code}{arithmetic.c}
+#include <stdio.h>
+
+int
+main (int   argc,
+      char *argv[])
+{
+    int x = 1234;
+    int y = 73;
+
+    /* Addition */
+    printf("%d + %d = %d", x, y, x + y);
+
+    /* Subtraction */
+    printf("%d - %d = %d", x, y, x - y);
+
+    /* Multiplication */
+    printf("%d * %d = %d", x, y, x * y);
+
+    /* Division */
+    printf("%d / %d = %d", x, y, x / y);
+
+    return 0;
+}
+\end{code}
+
 \section{printf() and scanf()}
 
 \section{Questions}



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