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 variable in c example?
Explain how can I read and write comma-delimited text?
What is the difference between text and binary i/o?
What is dynamic dispatch in c++?
How can I delete a file?
What is structure in c explain with example?
Explain the use of fflush() function?
Why we not create function inside function.
please explain clearly about execution of c program in detail,in which stage are the printf sacnf getting into exeecutable code
Why do we use namespace feature?
Is c procedural or object oriented?
How variables are declared in c?
How old is c programming language?
Why static is used in c?
What is the difference between the expression “++a” and “a++”?