#include
using namespace std;
int mul(int a,int b){
if(a==0 || b==0){
return 0;
}
if(a==1){
return b;
}
if (b==1){
return a;
}
if(a==-1){
return -b;
}
if(b==-1){
return -a;
}
if(a>0 and b<0){
return a+mul(a,b-1);
}
else if(a>0 and b<0){
return b+mul(a-1,b);
}
else if(a<0 and b>0){
return a+mul(a,b-1);
}
else if(a<0 and b<0){
return -a+mul(-a,-b-1);
}
else{
return 0;
}
}
int main(){
int a,b;
cin>>a>>b;
cout<<mul(a,b)<<endl;
return 0;
}
Why My code is not working for -ve numbers it is giving segmentation fault.