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


Please Help Members By Posting Answers For Below Questions

What is variable in c example?

592


Explain how can I read and write comma-delimited text?

652


What is the difference between text and binary i/o?

590


What is dynamic dispatch in c++?

556


How can I delete a file?

628






What is structure in c explain with example?

634


Explain the use of fflush() function?

626


Why we not create function inside function.

1747


please explain clearly about execution of c program in detail,in which stage are the printf sacnf getting into exeecutable code

1705


Why do we use namespace feature?

581


Is c procedural or object oriented?

580


How variables are declared in c?

571


How old is c programming language?

575


Why static is used in c?

620


What is the difference between the expression “++a” and “a++”?

650