Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Program Lab2_2;
- {Uses
- System.SysUtils;}
- Function ReadNumPositive(): Integer;
- Var
- Num: Integer;
- IsCorrect: Boolean;
- Begin
- Repeat
- IsCorrect := True;
- Try
- Read(Num);
- Except
- Write('Symbols have been entered or exceeding permissible limits. Enter a valid value: ');
- IsCorrect := False;
- End;
- If (IsCorrect) And (Num < 0) Then
- Begin
- IsCorrect := False;
- Write('A number less than zero was entered. Enter a valid value: ');
- End;
- Until IsCorrect;
- ReadNumPositive := Num;
- End;
- Function CountRoot(Num: Integer): Integer;
- Var
- MAX: Integer;
- Begin
- MAX := Round(Exp(Ln(Num) / 3));
- CountRoot := MAX;
- End;
- Procedure ShowCombinations(var K: Integer; MAX, Num: Integer);
- Var
- X, Y, Z: Integer;
- Begin
- For X := 0 to MAX do
- For Y := 0 to MAX do
- For Z := 0 to MAX do
- If X * X * X + Y * Y * Y + Z * Z * Z = Num then
- Begin
- Writeln(X, ' ', Y, ' ', Z);
- Inc(K);
- End;
- End;
- Procedure ShowResult(K: Integer);
- Begin
- If K <> 0 Then
- Write('Finite number of combinations: ', K)
- Else
- Write('There are no combinations.');
- End;
- Procedure WhatDoesTheProgramDo();
- Begin
- Writeln('The program indicates all triples of numbers X, Y, Z, that satisfy the condition: X^3 + Y^3 + Z^3 = Num.');
- End;
- Var
- Num, X, Y, Z, K, MAX: Integer;
- Begin
- WhatDoesTheProgramDo();
- K := 0;
- Write('Enter the number: ');
- Num := ReadNumPositive();
- MAX := CountRoot(Num);
- ShowCombinations(K, MAX, Num);
- ShowResult(K);
- End.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement