summaryrefslogtreecommitdiff
path: root/reference/C/EXAMPLES/modulo.c
diff options
context:
space:
mode:
Diffstat (limited to 'reference/C/EXAMPLES/modulo.c')
-rw-r--r--reference/C/EXAMPLES/modulo.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/reference/C/EXAMPLES/modulo.c b/reference/C/EXAMPLES/modulo.c
new file mode 100644
index 0000000..7d10986
--- /dev/null
+++ b/reference/C/EXAMPLES/modulo.c
@@ -0,0 +1,24 @@
+
+/************************************************************************
+ *
+ * Purpose: Program to demonstrate the '%' operator.
+ * Author: M J Leslie
+ * Date: 19-Mar-94
+ *
+ ************************************************************************/
+
+#include <stdio.h>
+
+main()
+{
+ int i,j;
+ /* The modulo is the remainder of
+ after an integer division */
+
+ printf("14 modulo 7 (14%%7) is %i\n", 14%7); /* answer is 0 */
+ printf("15 modulo 7 (15%%7) is %i\n", 15%7); /* answer is 1 */
+
+ i=10; j=6;
+
+ printf("%i modulo %i (%i%%%i) is %i\n",i,j,i,j,i%j); /* answer is 4 */
+}