R
R
Roma2015-10-09 12:28:57
Pascal
Roma, 2015-10-09 12:28:57

How to raise to the power of 2n?

365c8980d7804716bea29ad58a893e81.PNG
This must be done through a for to do loop.
I don't know how to raise to the 2n power. Where n is an arbitrary number to be entered from the keyboard.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Anton Fedoryan, 2015-10-09
@k4roma

I can’t say how it looks in Pascal, I don’t have a compiler at hand, but in Python it’s something like this:

x = 3
n = 4
xn = x
# (1 + 1)
sum = 2
for i in range(2, (2 * n + 1)):
  xn *= x
  sum *= (1 + xn)

Those. x and n values ​​are initially set (or entered from the keyboard, it doesn't matter).
The first factor is always = 2 because (1 + 1).
We start the cycle from 2 to 2 * n
In order not to constantly raise x to a power, we gradually multiply it by ourselves.
And we multiply all this by the previously obtained multipliers.
UpD: here is the working code in Pascal. Specially installed compiler FreePascal 2.6.4
program hello;
  var
  x, n, xn, i: integer;
  sum: int64;
  begin
        x := 3;
        n := 4;
        sum := 2;
        xn := x;
        for i := 2 to (2 * n) do
                begin
                        xn := xn * x;
                        sum := sum * (1 + xn);
                        writeln(sum);
                end;
        writeln(sum);
        readln();
  end.

V
Vladimir Martyanov, 2015-10-09
@vilgeforce

Multiply the entered n by two, raise the number to this power. It is no different from raising to any other power.

E
Elena, 2015-10-09
@keeper81

Or you can simply first raise the given number to the second power and raise the already received number to the power n. Thereby reducing the number of operations.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question