12.5.. Napisati program koji će za učitanu vrijednost K iN izračunati vrijednost izraza i ispisati::
Opis rješenja:
Listing programa:
PROGRAM p12900052;
USES
WinCRT;
VAR
n,k: 1..MAXINT;
i: 0..MAXINT;
znak : -1..1;
s: Real;
BEGIN
Write('n=');
Readln(n);
Write('k=');
Readln(k);
znak := 1;
s:=0;
i := 1;
WHILE 0 <= n DO
BEGIN
s := s + znak *(i+1)/(k+i);
znak := -znak;
i := i + 1;
END;
Writeln('s=', s:6:2);
END.
II Varijanta
PROGRAM p12900052_2;
USES
WinCRT;
VAR
i,n,k : Integer;
s,s1,s2 :Real;
BEGIN
Write('n=');
Readln(n);
Write('k=');
Readln(k);
s:=0;
s1:=0;
s2:=0;
i := 0;
REPEAT
IF i MOD 2 <>0 THEN
s1:=s1+(i+1)/(k+i)
ELSE
s2:=s2+(i+1)/(k+i);
i := i + 1;
UNTIL i > n;
s := s1 - s2;
WRITELN('s=',s:6:2)
END.
Index
|
|