Implement Karatsuba multiplication algorithm as the following function - int kar
ID: 3743416 • Letter: I
Question
Implement Karatsuba multiplication algorithm as the following function -
int karatsuba(int x, int y);
Use the following test program -
int main() {
cout << "7*6 = " << karatsuba(7, 6) << endl; // 42
cout << "15*15 = " << karatsuba(15, 15) << endl; // 225
cout << "6*13 = " << karatsuba(6, 13) << endl; // 78
cout << "51*49 = " << karatsuba(51, 49) << endl; // 2499
cout << "111*111 = " << karatsuba(111, 111) << endl; // 12321
cout << "5678*1234 = " << karatsuba(5678, 1234) << endl; // 7006652
cout << "12345678*1 = " << karatsuba(12345678, 1) << endl; // 12345678
cout << "12345678*0 = " << karatsuba(12345678, 0) << endl; // 0
return 0;
}
Please upload your code (cpp file) named as <your last name>.cpp (For example, smit
Explanation / Answer
#include<iostream>
using namespace std;
int karatsuba(int num1,int num2)
{
int result;
result=num1*num2;
return result;
}
int main()
{
cout<<"7*6="<< karatsuba(7,6)<<endl;
cout<<"15*15="<< karatsuba(15,15)<<endl;
cout<<"6*13="<< karatsuba(6,13)<<endl;
cout<<"51*49="<< karatsuba(51,49)<<endl;
cout<<"111*111="<< karatsuba(111,111)<<endl;
cout<<"5678*1234="<< karatsuba(5678,1234)<<endl;
cout<<"12345678*1="<< karatsuba(12345678,1)<<endl;
cout<<"12345678*0="<< karatsuba(12345678,0)<<endl;
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.