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 are different types of variables in c?
There is a practice in coding to keep some code blocks in comment symbols than delete it when debugging. How this affect when debugging?
write a proram to reverse the string using switch case?
Write a program, where i have a grid with many cells, how many paths are possible from one point to other desired points.
How can you convert integers to binary or hexadecimal?
Tell us something about keyword 'auto'.
Not all reserved words are written in lowercase. TRUE or FALSE?
Explain about the functions strcat() and strcmp()?
How can I write data files which can be read on other machines with different word size, byte order, or floating point formats?
Where we use clrscr in c?
which is conditional construct a) if statement b) switch statement c) while/for d) goto
What are the disadvantages of a shell structure?
Which one to choose from 'initialization lists' or 'assignment', for the use in the constructor?
What are formal parameters?
Is register a keyword in c?