Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program Project1;
- {$APPTYPE CONSOLE}
- uses
- SysUtils, Math;
- type
- NumArr = array of integer;
- var
- count,i,j, PowN: integer;
- Numbers: NumArr;
- function Multiply(CurArr, InitArr:NumArr):NumArr;
- var
- FinArr: NumArr;
- range, lenCur, lenInit: integer;
- begin
- lenCur := high(CurArr) ; lenInit := high(InitArr) ;
- range:= lenCur + lenInit +1;
- SetLength(FinArr, range);
- for i:= 0 to lenCur do
- for j:= 0 to lenInit do
- FinArr[i+j]:= FinArr[i+j] + CurArr[i]*InitArr[j];
- Result:= FinArr;
- end;
- function PolynomPower (CurArr:numArr; powN:integer):NumArr;
- var
- i: integer;
- StArr: NumArr;
- begin
- SetLength(StArr,1);StArr[0] := 1;
- for i:= 1 to PowN do
- StArr := Multiply(StArr,CurArr);
- Result:= StArr;
- end;
- procedure printArray(TmpArr:NumArr);
- var i, tmp:integer;
- OutputArrStr: string;
- begin
- tmp:= high(TmpArr);
- OutputArrStr:= OutputArrStr + IntToStr(TmpArr[tmp]) + 'x^' + IntToStr(tmp);
- for i:= tmp-1 downto 0 do begin
- if sign(TmpArr[i]) = 1 then
- OutputArrStr:= OutputArrStr + '+'+IntToStr(TmpArr[i]) +'x^' + IntToStr(i)
- else if sign(TmpArr[i]) = 0 then
- Continue
- else
- OutputArrStr:= OutputArrStr + '-' + IntToStr(abs(TmpArr[i])) + 'x^' + IntToStr(i);
- end;
- Delete(OutputArrStr, Length(OutputArrStr)-2, 3);
- Writeln(OutputArrStr)
- end;
- function SetArray():NumArr;
- begin
- end;
- begin
- write('Enter the number of members: ');readln(count);
- SetLength(Numbers, count);
- for i:= count-1 downto 0 do begin
- write('x^',i,': '); readln(Numbers[i]); end;
- write('Enter Power: '); readln(powN);
- Numbers := PolynomPower(Numbers, powN);
- printArray(Numbers);
- readln;
- end.
Add Comment
Please, Sign In to add comment