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

Find the exact value. log81 3 A) 1 4 B) 1 8 C) 1 12 D) 1 16
Ni esperanza fallida, ni trabajos injustos, ni pena inmerecida Que tipo de figura literaria es:
What is a more academically sounding synonym for Hungry
What best describes literacy rate in North Africa
What is the difference between warm colors and cool colors? Give examples of each
What is a large fish swim swirly in the sea
What is a large fish swim swirly in the sea
Solve the system of equations. -5x + 2y =9
En philosophie notre question synthèse de cours est : nos croyances doivent-elle être rationnelles ? cependant je dois trouver une façon de reformuler la questi
which of the following is the best description of dickensons poetry