From 0887d8f96950a060a122e14ed2981182ff1eb37d Mon Sep 17 00:00:00 2001 From: Nguyễn Gia Phong Date: Sat, 28 Dec 2019 21:16:58 +0700 Subject: [usth/ICT2.1] Algorithm and Data Structures --- usth/ICT2.1/labwork/4/Ex1.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 usth/ICT2.1/labwork/4/Ex1.c (limited to 'usth/ICT2.1/labwork/4/Ex1.c') 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 + +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; +} -- cgit 1.4.1