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 difference between main and void main?
Find MAXIMUM of three distinct integers using a single C statement
How can you avoid including a header more than once?
In which language linux is written?
Can I use base-2 constants (something like 0b101010)? Is there a printf format for binary?
What is the difference between int main and void main in c?
What are the salient features of c languages?
Write a program for Overriding.
What is oops c?
Do you have any idea about the use of "auto" keyword?
Can we access the array using a pointer in c language?
What is the use of c language in real life?
How is a pointer variable declared?
Difference between Shallow copy and Deep copy?
Why & is used in scanf in c?