Multiplication using Recursion

#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.

Save your code on ide.codingblocks.com and then share its link…

@pratyush63 https://ide.codingblocks.com/s/223293

You have complicated your code. Also positive numbers, it is not giving the desired output.
Refer this:

@pratyush63 Thank u sir now I understood