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

is y=4x-5 proportional
how do you divide whole numbers by fractions
Why did spanish monarchs oppose the spread of protestantism?
which Radical Republican proposal for reconstruction was defeated by its opponents?
DEFG is a rectangle. DF = 5x - 3and EG = x + 5. Find the value of x and the length of each diagonal. a. x = 1, DF = 6, EG = 6 b. x = 2, DF = 7, EG = 12 c.
Which of the following is written correctly for a periodical citation? (Syng, par. 8). (Syng, 97). (Syng "Lord" 20). (Syng 22).
winnie wrote the following riddle .I am a number between 60 and 100
Jake and his little sister made gingerbread cookies for their school party. They decorated each cookie to look different. Jakes favorite cookie have orange hair
Michelle Raleigh budget budget one third of her monthly salary for entertainment if her entertainment bill of the month is $850 what is her monthly salary
What motivates Penelope to test Odysseus' identity