Write a C++ program to multiply two integers without using multiplication, division, bitwise operators, and loops


Write a C++ program to multiply two integers without using multiplication, division, bitwise operators, and loops

Sample Input: 8, 9
Sample Output: 72

Sample Input: -11, 19
Sample Output: -209

Sample Output:

72
-209

الأجوبة

ابحث عن مسائل برمجة سي بلس بلس | C++ programming بالانجليزي

#include <iostream>
  
using namespace std; 
int multiply_two_nums(int x, int y) 
{ 
    if(y == 0) 
    return 0; 
  
    if(y > 0 ) 
    return (x + multiply_two_nums(x, y-1 )); 
  
    if(y < 0 ) 
    return - multiply_two_nums(x, -y); 
}

int main() 
{ 
    cout << multiply_two_nums(8, 9) << endl; 
    cout << multiply_two_nums(-11, 19) << endl ;
    return 0; 
} 

محتاج مساعدة؟ تواصل مع مدرس اونلاين الان!