Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 3

#include <iostream>

#include <cstdlib>

using namespace std;

void modder1(int A, int B,int x, int y, int z);


void modder2(int A, int B,int x, int y, int z);
int main()
{
int a,A;
int b,B;
int z=0;

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;
}
}

cout<<"By modulus: "<<A%B<<endl<<endl;

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;
}

void modder1(int A, int B,int x, int y, int z)


{
do
{
z=x-y;
x-=y;
}
while (x>=y);

cout<<"The remainder of "<<A<<"/"<<B<<" is "<<z;


}

void modder2(int A, int B,int x, int y, int z)


{
do
{
z=x-y;
x-=y;
}
while (x>=y);

z*= -1;
cout<<"The remainder of "<<A<<"/"<<B<<" is "<<z;
}

You might also like