Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
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.
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.
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 questionAsk a Question
731 491 924 answers to any question