12.5.5. Napisati program koji će za učitanu vrijednost N izračunati vrijednost izraza i ispisati:
Listing programa:
PROGRAM p12500005;
USES WinCRT;
VAR
i,n,s1: Integer;
s,p: Real;
BEGIN
Write('n=');
Readln(n);
p:=1;
s := 0;
s1 := 0;
FOR i:=1 TO n DO
BEGIN
s1:=s1+i;
p:=p*i;
s:=s+s1/p;
END;
Writeln('s=',s:4:2);
END.
Za objašnjenje:
*** |
Listing programa |
Opis |
1 |
PROGRAM p12500005; |
|
2 |
USES WinCRT; |
|
3 |
VAR |
|
4 |
i,n,s1: Integer; |
|
5 |
s,p: Real; |
|
6 |
BEGIN |
|
7 |
Write('n='); |
|
8 |
Readln(n); |
|
9 |
p:=1; |
|
10 |
FOR i:=1 TO n DO |
|
11 |
BEGIN |
|
12 |
s1:=s1+i; |
|
13 |
p:=p*i; |
|
14 |
s:=s+s1/p; |
|
15 |
END; |
|
16 |
Writeln('s=',s:4:2); |
|
17 |
END. |
|
Ispis na ekranu:
Index
|
|