fork(1) download
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3.  
  4. int remainder;
  5.  
  6. int division(int p,int q){
  7.  
  8.  
  9. int quotient=1,divisor =q;
  10. /*if divisor and diviend are equal then quotient=1*/
  11. if(p==q){
  12. remainder=0;
  13. return 1;
  14. }
  15. /*if dividend is smaller than divisor then remainder=dividend*/
  16. if(p<q){
  17. remainder=p;
  18. return 0;
  19. }
  20. /*shift left till divisor > dividend*/
  21. while(p>=q){
  22.  
  23. q<<=1;
  24. quotient<<=1;
  25. }
  26. /*shift right for one time so that divisor become smaller than dividend*/
  27. q>>=1;
  28. quotient>>=1;
  29. /*again call division recurcively*/
  30. quotient+=division(p-q,divisor);
  31. return quotient;
  32. }
  33.  
  34. int main()
  35. {
  36. int a,b;
  37. scanf("%d %d",&a,&b);
  38. if(b)
  39. printf("%d",division(a,b));
  40. return 0;
  41. }
stdin
100 9
compilation info
prog.c:4: warning: built-in function ‘remainder’ declared as non-function
prog.c: In function ‘main’:
prog.c:37: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result
stdout
11