N
N
Nikikez2020-11-25 12:40:06
Pascal
Nikikez, 2020-11-25 12:40:06

Given a real number x and a natural number n. How to calculate without using the exponentiation operation?

12. Given a real number x and a natural number n.

5fbe275e8aa87021908454.jpeg

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vasily Bannikov, 2020-11-25
@Nikikez

n is a natural number, which immediately simplifies the task, because you don’t have to raise it to a negative or fractional power.
So in this case, you can implement exponentiation through a loop.
I hope I've given you enough hint so that you can come up with a solution yourself.

We write our Pow

program powDemo;

function pow(number: Real; exponent: Integer): Real;
var
i: Integer;
result: Real;
begin
   result := 1;
   for i := 1 to exponent do
       result := result * number;
   pow := result;
end;

begin
    writeln(pow(2, 3));
end.

Лет 10 на паскале не писал, но всего за 2 запроса в гугл нашёл, как писать циклы и функции.
Алгоритм возведения в степень всем известен.

D
dollar, 2020-11-25
@dollar

Write down on a piece of paper all the operations and the main mat. functions (Sqrt, Sin, Cos, Ln, etc.) that are available in the Pascal language.
Further, the solution will become obvious (of course, if you are friends with mathematics).
Powers of two are just a shift.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question