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;

 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.



[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 work all kind of Inputs. The
concept behind this is We need to Perform the Reverse Operation
performed on the Mutiplication Without '*' Opreator. Here we need to
Subtract the Second Number From the First Number Until First Number =
Second Number. That’s All.

For example, Assume that a=10, b=3. Here we need to do is Subtract the
Number 3 from the number 10 itself, until a=b. And we should make a
count for how many times we are doing like this, It is the Quotient
Value.

So, finally We get the Answer as 3 Times we subtract 3 from the Number
10. Because we are checking the Condition a=b everytime. So the is
the Quotient as 3. The Remainder will be stored itself in 'a' as 1.




#include
#include

void main()
{
int a,b,c;
clrscr();

printf(Enter 2 No.s :\n);
scanf(%d%d,a,b); // Read 2 Numbers

if(b==0) // Here we are Checking for the Divide By Zero Error
{
printf(\nDivide By Zero Error);
}

else
{
c=0; // Here c as Count, and we should initialize the Count value to
0.
while(a=b) // We Repeatedly Checking for the Condition a=b
{
a = a - b; // Subtract b from a, and the new result stored in 'a'
itself
c++; // Incrementing the Count
}

printf(\nQuotient = %d \n Remainder = %d,c,a); // Print Quotient and
Remainder
}

getch();
}


Thanks
ShashankThe Best Way To Escape From The Problem  is to Solve It
CSE,BIT Mesra

-- 
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.



[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 log(n), where the Quotient =~ N
 
** 

-- 
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.



[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 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.



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 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.



[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 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

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 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

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 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.



[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 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.- Hide quoted text -

 - Show quoted text -

-- 
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

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 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

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);
  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

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;

 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.