Re: [algogeeks] Re: Divide 2 nos. without DIVISON
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; temp |= ((a mask) i) 1; result = 1; if ( temp = b ) { result |= 1; temp -= b; } } return result; } On Sun, May 22, 2011 at 10:56 PM, Aakash Johari aakashj@gmail.comwrote: 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; temp = 1; temp |= ((a mask) i) 1; result = 1; if ( temp = b ) { result |= 1; temp ^= b; } } return result; } On Sun, May 22, 2011 at 10:29 PM, Aakash Johari aakashj@gmail.comwrote: try for 15 and 3 On Sun, May 22, 2011 at 10:22 PM, D.N.Vishwakarma@IITR deok...@gmail.com wrote: 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); 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 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 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. -- 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. -- **With Regards Deoki Nandan Vishwakarma IITR MCA Mathematics Department* * -- 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. -- -Aakash Johari (IIIT Allahabad) -- -Aakash Johari (IIIT Allahabad) -- -Aakash Johari (IIIT Allahabad) -- 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.
Re: [algogeeks] Re: Divide 2 nos. without DIVISON
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 and divisor till the point where dividend is less than divisor or their difference is zero. On Sun, May 22, 2011 at 1:22 AM, kunzmilan kunzmi...@atlas.cz wrote: 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 repeat adding zeroes, if necessary. kunzmilan -- 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.
Re: [algogeeks] Re: Divide 2 nos. without DIVISON
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 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.
Re: [algogeeks] Re: Divide 2 nos. without DIVISON
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 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.
Re: [algogeeks] Re: Divide 2 nos. without DIVISON
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 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 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. -- 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.
Re: [algogeeks] Re: Divide 2 nos. without DIVISON
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); 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 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 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. -- 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. -- **With Regards Deoki Nandan Vishwakarma IITR MCA Mathematics Department* * -- 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. -- -Aakash Johari (IIIT Allahabad) -- 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.
Re: [algogeeks] Re: Divide 2 nos. without DIVISON
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; temp = 1; temp |= ((a mask) i) 1; result = 1; if ( temp = b ) { result |= 1; temp ^= b; } } return result; } On Sun, May 22, 2011 at 10:29 PM, Aakash Johari aakashj@gmail.comwrote: 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); 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 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 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. -- 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. -- **With Regards Deoki Nandan Vishwakarma IITR MCA Mathematics Department* * -- 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. -- -Aakash Johari (IIIT Allahabad) -- -Aakash Johari (IIIT Allahabad) -- 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.