C++ program to multiply two numbers using addition "+" operator.
C++ Program to multiply two numbers using addition
#includeOutputusing 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; }
Enter two integers 4 5 4 X 5 = 20
Recommended Posts