write a program for 7*8 = 56 ? without using * multiply
operator ? output = 56
Answer Posted / pavan_mustyala
Method1:
optimised code is to "left shift" the number 7 by 3 times.
Reason: 8 is (2 raised to power 3). So (7 * 8) is
equivalent to (((7*2)*2)*2). To multiply a number by 2,
shift it by 1 bit Left.
Method2:
Not optimised but it works. Addition in a loop.
int func()
{
int i;
int result = 0;
for(i = 0; i < 8; i++)
{
result = result + 7;
}
return result;
}
| Is This Answer Correct ? | 14 Yes | 4 No |
Post New Answer View All Answers
What is the right type to use for boolean values in c? Is there a standard type?
What is meant by recursion?
What is the difference between exit() and _exit() function in c?
What is the difference between ‘g’ and “g” in C?
Which one would you prefer - a macro or a function?
What is the correct declaration of main?
What are qualifiers and modifiers c?
swap 2 numbers without using third variable?
Calculate 1*2*3*____*n using recursive function??
write a program to find out prime number using sieve case?
Given an array of 1s and 0s arrange the 1s together and 0s together in a single scan of the array. Optimize the boundary conditions?
A float occupies 4 bytes in memory. How many bits are used to store exponent part? since we can have up to 38 number for exponent so 2 ki power 6 6, 6 bits will be used. If 6 bits are used why do not we have up to 64 numbers in exponent?
all c language question
What is call by reference in functions?
What will the code below print when it is executed? int x = 3, y = 4; if (x = 4) y = 5; else y = 2; printf ("x=%d, y=%d ",x,y);