Professional Documents
Culture Documents
Remrem
Remrem
#include <cstdlib>
cout<<"Remainder me."<<endl;
cout<<"Enter the numerator: ";
cin>>a;
cout<<"Enter the denominator: ";
cin>>b;
cout<<endl;
A=a;
B=b;
int x= abs(A);
int y= abs(B);
if ((a==0)and(b==0))
{
cout<<"Invalid: INDETERMINATE";
return 0;
}
else if ((a==0)or(b==0))
{
if (a==0)
{
cout<<"By modulus: "<<A%B<<endl<<endl;
cout<<"The remainder of "<<a<<"/"<<b<<" is 0.";
return 0;
}
else
{
cout<<"Invalid: UNDEFINED";
return 0;
}
}
if (a==b)
{
cout<<"The remainder of "<<a<<"/"<<b<<" is 0.";
return 0;
}
else if (x==y)
{
cout<<"The remainder of "<<a<<"/"<<b<<" is 0.";
return 0;
}
else if (b==1)
{
cout<<"The remainder of "<<A<<"/"<<B<<" is 0.";
return 0;
}
else if (x<y)
{
cout<<"The remainder of "<<A<<"/"<<B<<" is "<<A;
return 0;
}
else if (a<0)
{
if (x<y)
{
cout<<"The remainder of "<<A<<"/"<<B<<" is "<<A;
return 0;
}
else
{
modder2(A,B,x,y,z);
return 0;
}
}
else if (b<0)
{
if (x<y)
{
cout<<"The remainder of "<<A<<"/"<<B<<" is "<<A;
return 0;
}
else
{
modder1(A,B,x,y,z);
return 0;
}
}
else
{
modder1(A, B, x, y, z);
return 0;
}
return 0;
}
z*= -1;
cout<<"The remainder of "<<A<<"/"<<B<<" is "<<z;
}