maddygroves2986 maddygroves2986
  • 14-09-2019
  • Computers and Technology
contestada

Write an efficient C++ function that takes any integer value i and returns 2^i ,as a long value. Your function should not multiply 2 by itself i times; there are much faster ways of computing 2^i.

Respuesta :

ExieFansler ExieFansler
  • 18-09-2019

Answer:

long power(int i)

{

   return pow(2,i);

}

Explanation:

The above written function is in C++.It does not uses loop.It's return type is long.It uses the function pow that is present in the math library of the c++.It takes two arguments return the result as first argument raised to the power of second.

for ex:-

pow(3,2);

It means 3^2 and it will return 9.

Answer Link

Otras preguntas

If 3x=0, what is the value of 1+x+x^2
Which of the following occurs during artificial selection, but not during natural selection? A. Selection pressures result in only certain traits from a popula
Points A,B,C,D, and E are collinear and in that order. Find AC if AE = x+50 and CE = x+32.
Around 80% of India's population practices which religion?
Solve using substitution method.y=36-9x 3x+y/3=12
Starting at a certain speed, a bicyclist travels 200m. Suppose the bicyclist undergoes a constant acceleration of 1.20m/s squared. If the final speed is 25.0m/s
Please Graph 4x + 6y = 12 step by step
Find the coordinates of the midpoint of HX H(0,0) and X(8,4)
what is describes the steps you use during an experiment called??
Y=5X-6 how would you solve for x?