Learn How To Multiply Two Numbers without using Multiplication (*) Operator in C Programming Language. We generally use asterisk operator (*) to find the product of two numbers. Here, we shall use the + operator to find the product of the numbers. Alternatively, two numbers can be multiplied using Bitwise Operators.
The first code to find the product of two numbers without using multiplication operator (*) makes use of the addition (+) operator. If you want to multiply two integers without arithmetic operators, then you will have to use the bitwise operators which is demonstrated in the second program. It, therefore, uses bitwise shift operators.
C Program To Multiply Two Numbers without using * Operator
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | #include<stdio.h> int main() { int product = 0, a, b, count; printf("\nEnter First Number:\t"); scanf("%d", &a); printf("\nEnter Second Number:\t"); scanf("%d", &b); for(count = 0; count < b; count++) { product = product + a; } printf("\nProduct of %d and %d:\t%d\n", a, b, product); return 0; } |
C Program To Multiply Two Numbers using Bitwise Operators
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | #include<stdio.h> int main() { int product = 0, num1, num2, a, b, count; printf("\nEnter First Number:\t"); scanf("%d", &a); printf("\nEnter Second Number:\t"); scanf("%d", &b); num1 = a; num2 = b; while(num1) { if(num1 % 2 == 1) { product = product + num2; } num1 >>= 1; num2 <<= 1; } printf("\nProduct of %d and %d:\t%d\n", a, b, product); return 0; } |
Output

If you have any compilation error or doubts in this C program to Multiply Two Integers using Bitwise Operators, let us know about it in the comment section below.