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

  • How to multiply two numbers using addition "+" operator only in C++.

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