summaryrefslogtreecommitdiff
path: root/userspace/div.c
diff options
context:
space:
mode:
Diffstat (limited to 'userspace/div.c')
-rw-r--r--userspace/div.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/userspace/div.c b/userspace/div.c
new file mode 100644
index 0000000..595084e
--- /dev/null
+++ b/userspace/div.c
@@ -0,0 +1,23 @@
+// divide one param by another //
+// can be easily be used to provoke division by zero excpetion //
+
+#include <stdio.h>
+#include <stdlib.h>
+
+int main(int argc, char **argv)
+{
+ if (argc!=3)
+ {
+ printf("Divide two integers and print result \n");
+ printf("usage : %s [quotient] [divisor]\n",argv[0]);
+ return EXIT_FAILURE;
+ }
+
+ int q=atoi(argv[1]);
+ int d=atoi(argv[2]);
+ printf("Divide %i by %i\n",q,d);
+ printf("%i / %i = %i\n",q,d,q/d);
+ printf("%i mod %i = %i\n",q,d,q%d);
+
+ return EXIT_SUCCESS;
+}