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

Opis rješenja:

Listing programa:

PROGRAM p12910036;
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;
    IF i mod 3 = 0 THEN 
      BEGIN
        s := s + znak * k * p;
        znak := -znak;
      END;
    i := i + 1;
  UNTIL i > n;
  Writeln('s=',s:4:0);
END.

II Varijanta
PROGRAM p12910036_2;
USES
 WinCRT;
VAR
  i,n, k: Integer;
  s, p, s1, s2 , p1: Real;
BEGIN
  Write('n=');
  Readln(n);
  Write('k=');
  Readln(k);
  s := 0;
  s1:=0;
  s2:=0;
  p:=1;
  i := 1;
  REPEAT
    p := p * i;
    IF i mod 6 = 0 THEN 
      s1 := s1 + p * k;
    IF i mod 6 = 3 THEN 
      s2 := s2 + p * k;
    i := i + 1;
  UNTIL i > n;
  s := s2 - s1;
  Writeln('s=',s:4:2);
END.

Index