This is the code for calculating a*b without using " * " operator. It’s giving a wrong answer. Why?
Calculating a*b without using " * "
//Calulate ab without using '’ operator
#include
using namespace std;
int mul(int a, int b){
//Base Case
if(b==1)
return a;
//Recursive Case
return a+mul(a, b-1);
}
int main(){
int a, b;
cin>>a>>b;
cout<<mul(a, b)<<endl;
}
later one gives correct output
in previous one you have not called the function that’s why it is giving wrong ans
modified code
i hope this help
if you have more doubts regarding this feel free to ask
if your doubt is resolved mark it as resolved from your doubt section inside your course
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.