Find the product of a & b without using the operator *

>find the product of a & b without using the operator *
I'm not the only guy who solved this by not using a for loop and instead dividing a by the reciprocal of b, right?
Am I retarded?

I mean, I guess I wasn't in the context of a class and therefore didn't know that I was supposed to use a for loop.

generally, when a problem tells you not to use multiplication, it's also bad form to use division.

also,

It depends if the mean
>don't *explicitly* use *
or
>don't multiply a and b

You multiplied a and b but you didn't explicitly used *. I wouldn't do the same as you tho.

your method is superior user

for loop would only work with ints

I've done this in binary by using addition and shifting

>tfw cant do this
maximum ironing

>Not knowing that multiplication is just repeated addition

OB BLS.

this

for (i = 0; i < b; i++){
product += a;
}

/thread

Of course you'd have to make this a bit more complicated if you're multiplying non-integers

>Am I retarded?
Yes. Your method doesn't work at all when b is 0. Also, assuming you aren't using arbitrary precision arithmetic, you will either potentially lose information if you do integer division, or potentially get a rounding error if you use IEEE.

Operates in O(b), when it could operate in O(log(b)) if you used shift and add.

-3 * -5 = ???

a / (1 / b) = a * b

LOOK IT'S Ruby !OffRailsfU THANKS GOD HE IS USING HIS AMAZING HACKER TRIPCODE (WOW HOW DID YOU DO THIS?!) SO WE KNOW THE POST MUST BE HIGH DEFINITION QUALITY!!!

Except for b = 0

use a try catch jesus

You flatter me, user, but I'm not Jesus.

i flattered ur mom last nite m8

Now that I think about things, it should also fail for multipliers of 2 or greater.

If b >= 2, 1 / b = 0 using integer division. Dividing by this always causes an arithmetic exception.

Why are there so many tripfags recently on every damn board?

Reddit invasion, most likely thanks to Sup Forums and Sup Forums.

Using Bitwise

#include

main()
{
int a, b, result;
printf("\nEnter the numbers to be multiplied:");
scanf("%d%d", &a, &b); // a > b
result = 0;
while (b != 0) // Iterate the loop till b == 0
{
if (b & 01) // Bitwise & of the value of b with 01
{
result = result + a; // Add a to result if b is odd .
}
a=1; // Right shifting the value contained in 'b' by 1.
}
printf("nResult:%d",result);
}

You are suppose to use recursion

>I'm not the only guy who solved this by not using a for loop and instead dividing a by the reciprocal of b, right?

Explain to me, Bobby, how that works with integer types.

Then, for bonus points, explain to me how that works with floating point types.

>not using inline assembly