about summary refs log tree commit diff
path: root/usth/ICT2.1/labwork/4/Ex1.c
diff options
context:
space:
mode:
Diffstat (limited to 'usth/ICT2.1/labwork/4/Ex1.c')
-rw-r--r--usth/ICT2.1/labwork/4/Ex1.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/usth/ICT2.1/labwork/4/Ex1.c b/usth/ICT2.1/labwork/4/Ex1.c
new file mode 100644
index 0000000..4d0ab5d
--- /dev/null
+++ b/usth/ICT2.1/labwork/4/Ex1.c
@@ -0,0 +1,25 @@
+/*
+ * Multiply two natural numbers from stdin and print the result to stdout.
+ * This is free and unencumbered software released into the public domain.
+ */
+
+#include <stdio.h>
+
+int multiply(int a, int b)
+{
+	if (a > 0)
+		return multiply(a - 1, b) + b;
+	if (a < 0)
+		return multiply(a + 1, b) - b;
+	return 0;
+}
+
+int main()
+{
+	int a, b;
+
+	scanf("%d %d", &a, &b);
+	printf("%d\n", multiply(a, b));
+
+	return 0;
+}