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

الأجوبة

#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; 
} 
هل كان المحتوى مفيد؟

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...