We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents ad2a72c + d67d9c4 commit 0f0437eCopy full SHA for 0f0437e
C++/recursion/productOfTwoNo.cpp
@@ -0,0 +1,28 @@
1
+#include <iostream>
2
+using namespace std;
3
+int multrecur(int n, int m)
4
+{
5
+ if (n > 0 && m < 0) {
6
+ return multrecur(m, n);
7
+ }
8
+ else if (n < 0 && m < 0) {
9
+ return multrecur((-1 * n), (-1 * m));
10
11
+ if (n > m) {
12
13
14
+ else if (m != 0) {
15
+ return n + multrecur(n, m - 1);
16
17
+ else {
18
+ return 0;
19
20
+}
21
+int main()
22
23
+ cout << "10 * 5 = " << multrecur(10, 5) << endl;
24
+ cout << "10 * (-5) = " << multrecur(10, -5) << endl;
25
+ cout << "(-10) * 5 = " << multrecur(-10, 5) << endl;
26
+ cout << "(-10) * (-5) = " << multrecur(-10, -5) << endl;
27
28
0 commit comments