Given a integer x, write a function that multiplies x with 3.5 and returns the integer result. You are not allowed to use %, /, *.

Examples:
Input: 2
Output: 7

Input: 5
Output: 17 (Ignore the digits after decimal point)

Solution:
1. We can get x*3.5 by adding 2*x, x and x/2. To calculate 2*x, left shift x by 1 and to calculate x/2, right shift x by 2.

[pastacode lang=”c” manual=”%23include%20%3Cstdio.h%3E%0A%20%0Aint%20multiplyWith3Point5(int%20x)%0A%7B%0A%20%20return%20(x%3C%3C1)%20%2B%20x%20%2B%20(x%3E%3E1)%3B%0A%7D%20%20%20%20%0A%20%0A%2F*%20Driver%20program%20to%20test%20above%20functions*%2F%0Aint%20main()%0A%7B%0A%20%20int%20x%20%3D%204%3B%20%0A%20%20printf(%22%25d%22%2C%20multiplyWith3Point5(x))%3B%0A%20%20getchar()%3B%0A%20%20return%200%3B%0A%7D” message=”c” highlight=”” provider=”manual”/]

2. Another way of doing this could be (8*x – x)/2 (See below code). Thanks to ajaym for suggesting this.

[pastacode lang=”c” manual=”%23include%20%3Cstdio.h%3E%0Aint%20multiplyWith3Point5(int%20x)%0A%7B%0A%20%20return%20((x%3C%3C3)%20-%20x)%3E%3E1%3B%0A%7D” message=”c” highlight=”” provider=”manual”/] [ad type=”banner”]