C++ Program to Multiply Two Numbers Without Using '*' Operator

C++ program to multiply two numbers using addition "+" operator.


C++ Program to multiply two numbers using addition

#include 

using namespace std;

int multiply(int a, int b) {
  int result = 0;
  // Add integer a to result b times
  while(b != 0) {
      result = result + a;
      b--;
  }
  return result;
}

int main () {
  int a, b;
  cout << "Enter two integers" << endl;
  cin >> a >> b;
  cout << a << " X " << b << " = " << multiply(a, b);
  return 0;
}
Output
Enter two integers
4 5
4 X 5 = 20

Recommended Posts
C++ Program to Add Two Distances in Inch and Feet
C++ Program to Store Information of an Employee in Structure
C++ Program to Add Two Complex Numbers Using Structure
C++ Program to Find Area and Circumference of a Circle
C++ Program to Find Area and Perimeter of Parallelogram
C++ Program to print ASCII Value of All Alphabets
C++ Program to Find Power of a Number
All C++ Programs