1.

Multiply an Integer Number by 2 Without Using Multiplication Operator

Answer»

#include<stdio.h>int main(){ int x; printf("Enter a number: "); scanf("%d",&AMP;x); printf("%d", x<<1); return 0;}

The left shift OPERATOR shifts all bits towards the left by a certain number of specified bits. The expression x<<1 always returns x*2. Note that the shift operator doesn’t work on floating-point values.

For multiple of x by 4, use x<<2. Similarly x<<3 MULTIPLY x by 8. For multiple of the number x by 2^n, use x<<n.



Discussion

No Comment Found