Advertisement
LisunovaMaryna

lab2.2 delphi

Oct 29th, 2023 (edited)
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.72 KB | None | 0 0
  1. Program Lab2_2;
  2.  
  3. {Uses
  4.     System.SysUtils;}
  5.  
  6. Function ReadNumPositive(): Integer;
  7. Var
  8.     Num: Integer;
  9.     IsCorrect: Boolean;
  10. Begin
  11.     Repeat
  12.         IsCorrect := True;
  13.         Try
  14.             Read(Num);
  15.         Except
  16.             Write('Symbols have been entered or exceeding permissible limits. Enter a valid value: ');
  17.             IsCorrect := False;
  18.         End;
  19.         If (IsCorrect) And (Num < 0) Then
  20.         Begin
  21.             IsCorrect := False;
  22.             Write('A number less than zero was entered. Enter a valid value: ');
  23.         End;
  24.     Until IsCorrect;
  25.     ReadNumPositive := Num;
  26. End;
  27.  
  28. Function CountRoot(Num: Integer): Integer;
  29. Var
  30.     MAX: Integer;
  31. Begin
  32.     MAX := Round(Exp(Ln(Num) / 3));
  33.     CountRoot := MAX;
  34. End;
  35.  
  36. Procedure ShowCombinations(var K: Integer; MAX, Num: Integer);
  37. Var
  38.   X, Y, Z: Integer;
  39. Begin
  40.   For X := 0 to MAX do
  41.         For Y := 0 to MAX do
  42.             For Z := 0 to MAX do
  43.                 If X * X * X + Y * Y * Y + Z * Z * Z = Num then
  44.                 Begin
  45.                     Writeln(X, ' ', Y, ' ', Z);
  46.                     Inc(K);
  47.                 End;
  48. End;
  49.  
  50. Procedure ShowResult(K: Integer);
  51. Begin
  52.     If K <> 0 Then
  53.         Write('Finite number of combinations: ', K)
  54.     Else
  55.         Write('There are no combinations.');
  56. End;
  57.  
  58. Procedure WhatDoesTheProgramDo();
  59. Begin
  60.     Writeln('The program indicates all triples of numbers X, Y, Z, that satisfy the condition: X^3 + Y^3 + Z^3 = Num.');
  61. End;
  62.  
  63. Var
  64.     Num, X, Y, Z, K, MAX: Integer;
  65.  
  66. Begin
  67.     WhatDoesTheProgramDo();
  68.     K := 0;
  69.     Write('Enter the number: ');
  70.     Num := ReadNumPositive();
  71.     MAX := CountRoot(Num);
  72.     ShowCombinations(K, MAX, Num);
  73.     ShowResult(K);
  74. End.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement