Search This Blog

Sunday, May 17, 2009

Multiply without *

How to multiple 1 by 31 without using "*" and "+" ?

key: use left shit operator "<<", which means "multiple by 2"
int main()
{

int
original = 1;
int
answer = (1 << 5) - original;
cout << "1 x 31 is:" << answer << endl;
}

No comments: