Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- MODULE z;
- FROM RealInOut IMPORT WriteReal;
- FROM InOut IMPORT WriteString, WriteLn, WriteCard, ReadCard;
- CONST
- dgr = 1;
- ggr = 1000;
- TYPE
- INTERVAL = [dgr..ggr];
- VAR
- sum : REAL;
- ok : BOOLEAN;
- n : CARDINAL;
- PROCEDURE SOR(n: CARDINAL; VAR ok: BOOLEAN): REAL;
- VAR
- sum : REAL;
- i : INTERVAL;
- BEGIN
- IF (n > dgr) AND (n < ggr) THEN
- ok := TRUE;
- sum := 1.0;
- FOR i := 2 TO n DO
- sum := sum + (1.0/FLOAT(i))
- END;
- RETURN sum
- ELSE
- ok := FALSE;
- RETURN 0.0
- END;
- END SOR;
- BEGIN
- WriteString('Enter the range, n: ');
- ReadCard(n);
- WriteLn;
- sum := SOR(n,ok);
- IF ok THEN
- WriteString('Sum of reciprocal up to');
- WriteCard(n,0);
- WriteString(' is: ');
- WriteReal(sum,0)
- ELSE
- WriteString('n is not in RANGE, modifies it in CONST!');
- WriteLn
- END
- END z.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement