Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int divide (int a, int b);
- int rmndr (int a, int b);
- int main ()
- {
- int a, b, quot, rem;
- printf("\nEnter dividend:");
- scanf("%d", &a);
- printf("\nEnter divisor:");
- scanf("%d", &b);
- if (b==0)
- printf("\nMath error\n");
- else {if (a==0)
- printf("\nQuotient is 0\n");
- else
- {
- quot=divide (a,b);
- rem=rmndr (a,b);
- printf("\n\n%d divided by %d is %d remainder %d\n\n",a,b,quot,rem);
- }}
- return 0;
- }
- int divide (int a, int b)
- {
- if(a<0 && b>0)
- {
- if(-a>=b)
- return (-1)+(divide(a+b,b));
- else
- return 0;}
- else if(a>0 && b<0)
- {
- if(a>=-b)
- return (-1)+(divide(a+b,b));
- else
- return 0;}
- else if (a>0 && b>0)
- {if(a>=b)
- return 1+(divide(a-b,b));
- else
- return 0;}
- else
- {if(-a>=-b)
- return 1+(divide(a-b,b));
- else
- return 0;}
- }
- int rmndr (int a, int b)
- {
- if(a<0 && b>0)
- {
- if(-a>b && -a!=b)
- return 1*(rmndr(a+b,b));
- else
- return a;}
- else if(a>0 && b<0)
- {
- if(a>-b)
- return 1*(rmndr(a+b,b));
- else if(a==-b)
- return 0;
- else
- return a;}
- else if (a>0 && b>0)
- {if(a>b&&a!=b)
- return 1*(rmndr(a-b,b));
- else
- return a;}
- else
- {if(-a>-b)
- return 1*(rmndr(a-b,b));
- else if(a==b)
- return 0;
- else
- return a;}
- /*if(a<0)
- a=-1*a;
- if(a==b)
- return 0;
- else if (a<b)
- return a;
- else if(a>b)
- return 1*rmndr(a-b,b);*/
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement