File tree 1 file changed +43
-0
lines changed
1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change
1
+ //Statement - You have to find out the product of two intergers without using "*" (multiplication) operator
2
+
3
+ //Application of shift operator to solve the problem
4
+
5
+ //Importing header files
6
+ #include <bits/stdc++.h>
7
+ using namespace std;
8
+
9
+ //Function to calculate the product
10
+ int multiply(int n, int m)
11
+ {
12
+ int product = 0;
13
+ int counter = 0;
14
+ while (m)
15
+ {
16
+ if (m % 2 == 1)
17
+ {
18
+ product += n << counter;
19
+ }
20
+ counter++;
21
+ m=m>>1;
22
+ }
23
+ return product;
24
+ }
25
+
26
+ int main()
27
+ {
28
+ int a, b;
29
+ //Accepting the numbers from the user
30
+ cout << "Enter first number- ";
31
+ cin >> a;
32
+ cout << "Enter second number- ";
33
+ cin >> b;
34
+ //Printing the final result
35
+ cout << "Product of the two numbers- " << multiply(a, b);
36
+ return 0;
37
+ }
38
+ /*-----------------
39
+ Sample Input
40
+ Enter first number- 34
41
+ Enter second number- 3
42
+ Product of the two numbers- 102
43
+ -------------------*/
You can’t perform that action at this time.
0 commit comments