Thursday, February 3, 2011

Multiplication??????

Here is a code to multiply two numbers without using * operator.

    
    while(~scanf("%d%d",&a,&b))
    {
        m=0;
        while(a)
        {
            if(a&1)
                m+=b;
            a>>=1;
            b<<=1;
        }
        printf("%d\n",m);
    }
Thanks to fR0DDY from India for this post.

No comments:

Post a Comment