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 difference between text and binary modes?
What is far pointer in c?
write a c program to find the sum of five entered numbers using an array named number
How many keywords are there in c?
Why is it important to memset a variable, immediately after allocating memory to it ?
What would happen to X in this expression: X += 15; (assuming the value of X is 5)
please send me the code for multiplying sparse matrix using c
How is a macro different from a function?
How do I get an accurate error status return from system on ms-dos?
Can a void pointer point to a function?
How arrays can be passed to a user defined function
What is the explanation for modular programming?
Explain zero based addressing.
write a c program to calculate sum of digits till it reduces to a single digit using recursion
What happens if header file is included twice?