here is the working code  :

#include<stdio.h>
 8: int dividend, divisor, remainder;
 9:
10: /* Division function Computes the quotient and remainder of two numbers
11: using bit shifting */
12: int division(int tempdividend, int tempdivisor) {
13:
14:     int quotient = 1;
15:
16:     if (tempdivisor == tempdividend) {
17:        remainder = 0;
18:        return 1;
19:     } else if (tempdividend < tempdivisor) {
20:        remainder = tempdividend;
21:        return 0;
22:     }
23:
24:     while (tempdivisor <= tempdividend) {
25:        /* Here divisor <>
26:           divisor and quotient */
27:        tempdivisor = tempdivisor << 1;
28:        quotient = quotient << 1;
29:     }
30:
31:     /* We have reached the point where divisor > dividend,
32:     therefore divide divisor and quotient by two */
33:     tempdivisor = tempdivisor >> 1;
34:     quotient = quotient >> 1;
35:
36:     /* Call division recursively for the difference to get the
37:     exact quotient */
38:     quotient = quotient + division(tempdividend - tempdivisor, divisor);
39:
40:     return quotient;
41: }
42:
43: /* Division of two numbers without using division operator */
44: void main() {
45:
46:      printf ("\nEnter the Dividend: ");
47:      scanf("%d", &dividend);
48:      printf("\nEnter the Divisor: ");
49:      scanf("%d", &divisor);
50:
51:      printf("\n%d / %d: quotient = %d", dividend, divisor,
division(dividend, divisor));
52:      printf("\n%d / %d: remainder = %d", dividend, divisor, remainder);
53:      getch();
54: }


On Sat, May 21, 2011 at 11:40 PM, punnu <punnu.gino...@gmail.com> wrote:

> Given 2 nos.  we need to divide them without performing divison.
> Please give a better solution than subtracting the nos. again and
> again.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to