R
R
Roma2015-10-12 03:54:24
Pascal
Roma, 2015-10-12 03:54:24

Calculate the approximate value of an infinite sum?

ac954573199448e4be1d6d3650fffb2d.PNG
Help, with explanations if not difficult.
I can't figure out how to write it all down.
while (...) do
or
repeat (...) until

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Fedoryan, 2015-10-26
@AnnTHony

program endless_sum;
var
  x, i, j: integer;
  y, sum: extended;

function power(x, n: integer): longint;
var
 a, b: integer;
begin
  if (n = 0) then power := 1;
  if (n = 1) then power := x
  else
    begin
     a := x;
     for b := 2 to n do
       a := a * x;
     power := a;
    end;
end;

begin
  i := 1;
  write('input x: ');
  readln(x);
  sum := x;
  y := power(-1, i) * power(x, 2 * i);
  for j := 1 to 2 * i do
    y := y / j;
  while (abs(y) > 0.0001) do
    begin
      sum := sum + y;
      i := i + 1;
      y := power(-1, i) * x;
      for j := 2 to 2 * i do
        y := y * x / j;
    end;
  writeln(sum:5:4);
  readln();
end.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question