Re: [algogeeks] Re: Divide 2 nos. without DIVISON

2011-05-23 Thread Aakash Johari
A modification in the above code, int divide(int a, int b) { int temp = 0; int result = 0; int mask, i; printf (a = %d, b = %d\n, a, b); temp = 0; for ( i = 30; i = 0; i-- ) { mask = 1 i; temp = 1;

[algogeeks] Re: Divide 2 nos. without DIVISON

2011-05-23 Thread bittu
I don't know u will be happy with this or not but let me explain in simplest way PS: i haven't used division operator anywhere but i also i haven't done using Bit Logic which is efficient then this one but below code work simplest way to understand This One is the Simply Logical. This will

[algogeeks] Re: Divide 2 nos. without DIVISON

2011-05-23 Thread sravanreddy001
@bittu.. Given 2 nos. we need to divide them without performing divison. *Please give a better solution than subtracting the nos. again and again.* The author has specifically mentioned this. The order of this algo will be log(n) since the numbers are represented in binary form. against

[algogeeks] Re: Divide 2 nos. without DIVISON

2011-05-22 Thread kunzmilan
On 22 kvě, 08:40, 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. Try to multiply the smaler number and by a suitable number, subtract the product, compare, and

Re: [algogeeks] Re: Divide 2 nos. without DIVISON

2011-05-22 Thread ankit sambyal
Solve it using shift operator here is the crude algo : the procedure for the division algorithm, given a dividend and a divisor would be to left shift (multiply by 2) the divisor till it reaches dividend/2, then continue this routine with the the difference between the dividend and divisor

[algogeeks] Re: Divide 2 nos. without DIVISON

2011-05-22 Thread Dumanshu
Could u plz elaborate? about the quotient?? On May 22, 1:50 pm, ankit sambyal ankitsamb...@gmail.com wrote: Solve it using shift operator   here is the crude algo :  the procedure for the division algorithm, given a dividend and a divisor would be to left shift (multiply by 2) the divisor

Re: [algogeeks] Re: Divide 2 nos. without DIVISON

2011-05-22 Thread Puneet Ginoria
thnxx all.. i got the soln.. Qdumanshu: i was asking for quotient and remainder when we divide 2 nos. without actually dividing them... -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to

Re: [algogeeks] Re: Divide 2 nos. without DIVISON

2011-05-22 Thread Prakash D IT @ CEG
could someone explain the algo with an example? On Sun, May 22, 2011 at 8:21 PM, Puneet Ginoria punnu.gino...@gmail.comwrote: thnxx all.. i got the soln.. Qdumanshu: i was asking for quotient and remainder when we divide 2 nos. without actually dividing them... -- You received this

[algogeeks] Re: Divide 2 nos. without DIVISON

2011-05-22 Thread Dave
@Prakash: Think long division in binary. Dave On May 22, 11:33 am, Prakash D IT @ CEG cegprak...@gmail.com wrote: could someone explain the algo with an example? On Sun, May 22, 2011 at 8:21 PM, Puneet Ginoria punnu.gino...@gmail.comwrote: thnxx all.. i got the soln.. Qdumanshu: i

Re: [algogeeks] Re: Divide 2 nos. without DIVISON

2011-05-22 Thread Wladimir Tavares
a divide b while(b!=1){ a =1; b =1; } printf(%d\n,a); Wladimir Araujo Tavares *Federal University of Ceará * On Sun, May 22, 2011 at 1:33 PM, Prakash D IT @ CEG cegprak...@gmail.comwrote: could someone explain the algo with an example? On Sun, May 22, 2011 at 8:21 PM, Puneet

Re: [algogeeks] Re: Divide 2 nos. without DIVISON

2011-05-22 Thread Aakash Johari
try for 15 and 3 On Sun, May 22, 2011 at 10:22 PM, D.N.Vishwakarma@IITR deok...@gmail.comwrote: a divide b while(b!=1){ a =1; b =1; } printf(%d\n,a); On 5/22/11, Wladimir Tavares wladimir...@gmail.com wrote: a divide b while(b!=1){ a =1; b =1; } printf(%d\n,a);

Re: [algogeeks] Re: Divide 2 nos. without DIVISON

2011-05-22 Thread Aakash Johari
Try the following code: One can more optimize it. int divide(int a, int b) { int temp = 0; int result = 0; int mask, i; printf (a = %d, b = %d\n, a, b); temp = 0; for ( i = 30; i = 0; i-- ) { mask = 1 i;