multiply by 7

This is a discussion on multiply by 7 within the C Programming forums, part of the General Programming Boards category; how will you multiply a positive number by 7 without using straight forward multiplication and addition. best i could find ...

  1. #1
    Registered User
    Join Date
    Oct 2005
    Location
    Hyderabad, India
    Posts
    33

    multiply by 7

    how will you multiply a positive number by 7 without using straight forward multiplication and addition.

    best i could find out was
    Code:
    int func(int n){
    int temp = n<<3; //multiply by 8
    return temp - n;
    }
    any more interesting ways of solving this (i don't want subtraction either ???)

  2. #2
    Tropical Coder Darryl's Avatar
    Join Date
    Mar 2005
    Location
    Cayman Islands
    Posts
    503
    Code:
    int times7(int num)
    {
        return num/0.142857;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. multiply sections of printf format specifier?
    By space_ferret in forum C Programming
    Replies: 14
    Last Post: 03-27-2009, 10:54 AM
  2. Multiply using Bitwise
    By ganesh bala in forum C Programming
    Replies: 3
    Last Post: 01-29-2009, 11:35 PM
  3. multiply link list
    By mradul.exe in forum C Programming
    Replies: 5
    Last Post: 07-12-2008, 07:18 PM
  4. open file with numbers and multiply them
    By autopilot in forum C Programming
    Replies: 30
    Last Post: 09-10-2007, 04:48 PM
  5. How to multiply and Divide Huge int numbers
    By Dewayne in forum C++ Programming
    Replies: 3
    Last Post: 10-21-2004, 08:41 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21