12.7.. Napisati program koji će za učitanu vrijednost N izračunati vrijednost izraza i ispisati::

Opis rješenja:

Listing programa:

PROGRAM p12910321;
USES
 WinCRT;
VAR
  i, n, k: Integer;
  znak :-1..1;
  s, p: Real;
BEGIN
  Write('n=');
  Readln(n);
  Write('k=');
  Readln(k);
  znak := 1;
  s := 0;
  p:=1;
  i := 1;
  REPEAT
    p := p * i;
    s := s + znak * k * p;
    znak := -znak;
    i := i + 1;
  UNTIL i > n;
  Writeln('s=',s:4:0);
END.
II Varijanta
PROGRAM p12910321_2; USES WinCRT; VAR i,n, k: Integer; s, p, s1, s2 : Real; BEGIN Write('k='); Readln(k); Write('n='); Readln(n); s := 0; s1:=0; s2:=0; p:=1; i := 1; WHILE i <= n DO BEGIN p:=p*k*i; IF i mod 2 <>0 THEN s1 := s1 + p ELSE s2 := s2 + p; i := i + 1; END; s:=s1-s2; Writeln('s=',s:4:2); END.

Index