Program to divide a number without using / % * in C

Page 1 of 1

3 Replies - 5510 Views - Last Post: 07 May 2009 - 10:32 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=103925&amp;s=d599910e6d1e79358c216fcd7c10c0c3&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

#1 chaitrahosmane

Reputation: 0
• Posts: 5
• Joined: 07-May 09

Program to divide a number without using / % * in C

Posted 07 May 2009 - 09:50 AM

Program to divide a number without using / % * in C.
Please tell me what is the logic for this.?
Is This A Good Question/Topic? 0

Replies To: Program to divide a number without using / % * in C

#2 Jubb

Reputation: 6
• Posts: 88
• Joined: 06-May 09

Re: Program to divide a number without using / % * in C

Posted 07 May 2009 - 09:51 AM

Sounds like you want to do some bit shifting. Look it up. Maybe you could get away with putting some inline asm in there, you wouldn't *technically* be using / % or *.

#3 chaitrahosmane

Reputation: 0
• Posts: 5
• Joined: 07-May 09

Re: Program to divide a number without using / % * in C

Posted 07 May 2009 - 09:55 AM

Jubb, on 7 May, 2009 - 08:51 AM, said:

Sounds like you want to do some bit shifting. Look it up. Maybe you could get away with putting some inline asm in there, you wouldn't *technically* be using / % or *.

Yes i can do bit shifting. But bit shifting can multiply and divide only by 2.?
If i want to divide by 3 (i forgot to mention in the question) what i need to do..?

#4 baavgai

• Dreaming Coder

Reputation: 6379
• Posts: 13,629
• Joined: 16-October 07

Re: Program to divide a number without using / % * in C

Posted 07 May 2009 - 10:32 AM

chaitrahosmane, on 7 May, 2009 - 10:55 AM, said:

If i want to divide by 3 (i forgot to mention in the question) what i need to do..?

When I was little kid, instead of saying 10 divided by 3, we'd say 3 "goes into" 10. Division is nothing more than subtracting one number from another until you can't. It should be obvious if you think about it. The only tricky part is dealing the remainder.

Good luck.