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

how did the demand for indigo affect south Carolina plantation owners
How many years passed between Europeans first reaching the Americas and sugarcane being introduced in the West Indies?
Which of the following activities would have the most direct influence on lawmaking? Joining a special interest group Meeting with an elected official Talking a
what is an expression equivalent to (7x-5)-(3x-2)
How were the Americans able to win such an overwhelming victory at Trenton?
Why was Stalin able to establish such a strong Communist presence in Eastern Europe following World War II? The Soviet Union helped Eastern European countries t
describe why this graph in fact demonstrates this behavior
how did the demand for indigo affect south Carolina plantation owners
What was the most significant result of the Opium Wars?
five less than a number is more than twenty