Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int divide (int a, int b);
  4. int rmndr (int a, int b);
  5. int main ()
  6.  
  7. {
  8. int a, b, quot, rem;
  9. printf("\nEnter dividend:");
  10. scanf("%d", &a);
  11. printf("\nEnter divisor:");
  12. scanf("%d", &b);
  13. if (b==0)
  14. printf("\nMath error\n");
  15. else {if (a==0)
  16. printf("\nQuotient is 0\n");
  17. else
  18. {
  19. quot=divide (a,b);
  20. rem=rmndr (a,b);
  21. printf("\n\n%d divided by %d is %d remainder %d\n\n",a,b,quot,rem);
  22. }}
  23. return 0;
  24. }
  25.  
  26.  
  27. int divide (int a, int b)
  28. {
  29. if(a<0 && b>0)
  30. {
  31. if(-a>=b)
  32. return (-1)+(divide(a+b,b));
  33. else
  34. return 0;}
  35. else if(a>0 && b<0)
  36. {
  37. if(a>=-b)
  38. return (-1)+(divide(a+b,b));
  39. else
  40. return 0;}
  41. else if (a>0 && b>0)
  42. {if(a>=b)
  43. return 1+(divide(a-b,b));
  44. else
  45. return 0;}
  46. else
  47. {if(-a>=-b)
  48. return 1+(divide(a-b,b));
  49. else
  50. return 0;}
  51.  
  52. }
  53.  
  54.  
  55. int rmndr (int a, int b)
  56. {
  57. if(a<0 && b>0)
  58. {
  59. if(-a>b && -a!=b)
  60.  
  61. return 1*(rmndr(a+b,b));
  62. else
  63. return a;}
  64. else if(a>0 && b<0)
  65. {
  66. if(a>-b)
  67. return 1*(rmndr(a+b,b));
  68. else if(a==-b)
  69. return 0;
  70. else
  71. return a;}
  72. else if (a>0 && b>0)
  73. {if(a>b&&a!=b)
  74. return 1*(rmndr(a-b,b));
  75. else
  76. return a;}
  77. else
  78. {if(-a>-b)
  79. return 1*(rmndr(a-b,b));
  80. else if(a==b)
  81. return 0;
  82. else
  83. return a;}
  84. /*if(a<0)
  85. a=-1*a;
  86. if(a==b)
  87. return 0;
  88. else if (a<b)
  89. return a;
  90. else if(a>b)
  91. return 1*rmndr(a-b,b);*/
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement