Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program Project1;
- {$APPTYPE CONSOLE}
- {$R *.res}
- uses
- System.SysUtils, Math;
- type
- Mnogochlen = ^TMnogochlen;
- TMnogochlen = record
- Coefficient: Integer;
- Degree: Integer;
- Next: Mnogochlen;
- end;
- Function Equality (P, Q : Mnogochlen) : Boolean;
- Var
- IsEqual : Boolean;
- Begin
- IsEqual := True;
- while IsEqual and (Q <> nil) and (P <> nil) do
- Begin
- if (Q^.Degree <> P^.Degree) or (Q^.Coefficient <> P^.Coefficient) then
- Begin
- IsEqual := False;
- Break;
- End;
- Q := Q^.Next;
- P := P^.Next;
- End;
- Equality := IsEqual;
- End;
- Function Meaning (P : Mnogochlen; X : Integer) : Integer;
- Var
- Sum : Integer;
- Begin
- Sum := 0;
- while P <> nil do
- Begin
- Sum := Sum + P^.Coefficient * Round (Power (X, P^.Degree));
- P := P^.Next;
- End;
- Meaning := Sum;
- End;
- procedure Add (Var P : Mnogochlen; R,Q : Mnogochlen);
- var
- NewList : Mnogochlen;
- Begin
- P := nil;
- while (R <> nil) and (Q <> nil) do
- Begin
- New(NewList);
- NewList^.Next := nil;
- if (R = nil) or ((Q <> nil) and (R^.Degree < Q^.Degree)) then
- begin
- NewList^.Coefficient := Q^.Coefficient;
- NewList^.Degree := Q^.Degree;
- Q := Q^.Next;
- end
- else if (Q = nil) or ((R <> nil) and (R^.Degree > Q^.Degree)) then
- Begin
- NewList^.Coefficient := R^.Coefficient;
- NewList^.Degree := R^.Degree;
- R := R^.Next;
- End
- else
- Begin
- NewList^.Coefficient := R^.Coefficient + Q^.Coefficient;
- NewList^.Degree := R^.Degree + Q^.Degree;
- R := R^.Next;
- Q := Q^.Next;
- End;
- if P = nil then
- P := NewList
- else
- Begin
- NewList^.Next := P;
- P := NewList;
- End;
- End;
- End;
- function GetMnogochlen : Mnogochlen;
- Var
- I, N : Integer;
- Pt : Mnogochlen;
- Begin
- Writeln('Введите кол-во элементов списка:');
- Readln(N);
- New (Pt);
- for I := 0 to N - 1 do
- Begin
- New(Pt^.Next);
- Pt := Pt^.Next;
- Writeln('Введите коэффициент:');
- Readln(Pt^.Coefficient);
- Writeln('Введите степень многочлена:');
- Readln(Pt^.Degree);
- End;
- Pt^.Next := Nil;
- GetMnogochlen := Pt;
- End;
- var
- P, Q, R : Mnogochlen;
- Choose, X, Sum : Integer;
- Flag : Boolean;
- begin
- Writeln ('Введите номер интересующей вас функции, где:');
- Writeln ('1 - проверяет равенство 2 многочленов');
- Writeln ('2 - вычисляет значение многочлена в точке X');
- Writeln ('3 - суммирует 2 многочлена');
- Readln (Choose);
- if Choose = 1 then
- Begin
- P := GetMnogochlen();
- Q := GetMnogochlen();
- Flag := Equality (P, Q);
- if Flag then
- Writeln ('Равны')
- else
- Writeln ('Не равны')
- End;
- if Choose = 2 then
- Begin
- P := GetMnogochlen();
- Writeln ('Введите X:');
- Readln (X);
- Sum := Meaning (P, X);
- Writeln('Если в многочлен подставить X, то получится ',Sum);
- End;
- if Choose = 3 then
- Begin
- Q := GetMnogochlen();
- R := GetMnogochlen();
- Add(P, R, Q);
- while P <> nil do
- Begin
- Write(P^.Coefficient, 'а^',P^.Degree);
- P := P^.Next;
- End;
- End;
- Readln;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement