Thread: Division without operators

  1. #1
    Registered User
    Join Date
    Aug 2011
    Posts
    1

    Division without operators

    Please give hints to write program to divide 40 by 2 without using division operator.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Study what the other operators do.
    C Operator Precedence Table
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    Study the bitwise ones more carefully.

  4. #4
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Just bear in mind that the equivalence of some bitwise operations with some mathematical operations is only guaranteed for unsigned integral types: don't rely on such equivalences for int, float, double ....
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by jag_c View Post
    Please give hints to write program to divide 40 by 2 without using division operator.
    Overload the addition operator to divide.

    It's not crazy, it's C++!


    Quzah.
    Hope is the first step on the road to disappointment.

  6. #6
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,613

  7. #7
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    You might want to consider that log(a/b) == log(a) - log(b) in any base (for a and b both positive).

    No division on the right hand side of that expression .....
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. shifting? division?
    By kiros88 in forum C Programming
    Replies: 3
    Last Post: 06-09-2010, 02:10 PM
  2. true division in C ?
    By acidblue in forum C Programming
    Replies: 3
    Last Post: 12-03-2009, 11:22 PM
  3. Long Division
    By oogabooga in forum C Programming
    Replies: 9
    Last Post: 01-10-2008, 11:36 AM
  4. Division by 0
    By ajaxthegreater in forum A Brief History of Cprogramming.com
    Replies: 46
    Last Post: 10-08-2005, 04:21 PM
  5. Array Division
    By Rvaren in forum C++ Programming
    Replies: 2
    Last Post: 10-19-2002, 08:45 AM