12.5.17. Ispisati Pitagorine brojeve (x2 + y2 = z2, x,y<=40) i koliko ih ima.

Opis rješenja:

Za objašnjenje:

***

Listing programa

Opis

1

PROGRAM p12500017;

 

2

USES WinCRT;

 

3

VAR

 

4

  k,x,y: Integer;

 

5

  z:Real;

 

6

BEGIN

 

7

  k:=0;

 

8

  FOR x:=1 TO 40 DO

 

9

  FOR y:=1 TO 40 DO

 

10

  BEGIN

 

11

  z:=SQRT(SQR(x)+SQR(y));

 

12

  IF (z-round(z)=0) THEN

 

13

    BEGIN

 

14

      Writeln(x:4,y:4,round(z):4);

 

15

      k:=k+1;

 

16

    END

 

17

  END;

 

18

  Writeln(k,' trojki');

 

19

END.

 

Listing programa:

PROGRAM p12500017;
USES WinCRT;
VAR 
  k,x,y: Integer;
  z:Real;
BEGIN
  k:=0;
  FOR x:=1 TO 40 DO
  FOR y:=1 TO 40 DO
  BEGIN
  z:=SQRT(SQR(x)+SQR(y));
  IF (z-round(z)=0) THEN
    BEGIN
      Writeln(x:4,y:4,round(z):4);
      k:=k+1;
    END
  END;
  Writeln(k,' trojki');
END.

Ispis na ekranu:

Index