about summary refs log tree commit diff
path: root/usth/ICT2.1/labwork/4/Ex1.c
blob: 4d0ab5dd4f7553510ffffc9f272812812622e56e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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;
}