Thread: arithmatic operations without using them..

  1. #1
    Registered User
    Join Date
    Apr 2007
    Location
    India
    Posts
    14

    arithmatic operations without using them..

    Hi.

    I was reading a magzine.

    It had this question

    Without using /,% and * operators. write a function to divide a number by 3.

    Can anyone help...

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Strikes me as a homework problem. Ever heard of logarithms?

  3. #3
    Math wizard
    Join Date
    Dec 2006
    Location
    USA
    Posts
    582
    Division is really repeated subtraction. Just take a base number, such as 8152 and subtract 3 from it, but add 1 to the count. When the number to subtract is less than the amount to be subtracted, stop. You have the answer and the remainder, if any. Just adding and subtracting is used.
    High elevation is the best elevation. The higher, the better the view!
    My computer: XP Pro SP3, 3.4 GHz i7-2600K CPU (OC'd to 4 GHz), 4 GB DDR3 RAM, X-Fi Platinum sound, GeForce 460, 1920x1440 resolution, 1250 GB HDD space, Visual C++ 2008 Express

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    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.

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Threads merged with duplicate deleted.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #6
    Registered User
    Join Date
    Sep 2006
    Posts
    835
    Looks like an Adobe test from last year.

    http://www.google.com/search?q=%22wr...hl=en&filter=0

  7. #7
    Registered User
    Join Date
    Apr 2007
    Location
    India
    Posts
    14

    Thanks....

    THanks

  8. #8
    Registered User
    Join Date
    Apr 2007
    Location
    India
    Posts
    14

    Yes...it is from Adobe test paper...

    Quote Originally Posted by robatino View Post
    Looks like an Adobe test from last year.

    http://www.google.com/search?q=%22wr...hl=en&filter=0
    Yes...it is from Adobe test paper...

  9. #9
    Registered User
    Join Date
    Sep 2001
    Posts
    752
    Quote Originally Posted by ulillillia View Post
    Division is really repeated subtraction. Just take a base number, such as 8152 and subtract 3 from it, but add 1 to the count. When the number to subtract is less than the amount to be subtracted, stop. You have the answer and the remainder, if any. Just adding and subtracting is used.
    Presumably efficiency is part of the answer too. There is a logarithmic complexity solution to this problem
    Callou collei we'll code the way
    Of prime numbers and pings!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. doing floating operations using integer operations
    By ammalik in forum C Programming
    Replies: 10
    Last Post: 08-15-2006, 04:30 AM
  2. ROW OPERATIONS (finding Inverse) (im going crazy)
    By alexpos in forum C Programming
    Replies: 1
    Last Post: 11-20-2005, 10:07 AM
  3. Matrix and vector operations on computers
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 05-11-2004, 06:36 AM
  4. String Class Operations
    By Aidman in forum C++ Programming
    Replies: 10
    Last Post: 04-06-2003, 02:29 PM