Darkrai1337

Untitled

Dec 28th, 2021 (edited)
544
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.67 KB | None | 0 0
  1. program Project1;
  2.  
  3. {$APPTYPE CONSOLE}
  4.  
  5. uses
  6.   SysUtils, Math;
  7.  
  8. type
  9.   NumArr = array of integer;
  10. var
  11.   count,i,j, PowN: integer;
  12.   Numbers: NumArr;
  13. function Multiply(CurArr, InitArr:NumArr):NumArr;
  14. var
  15.   FinArr: NumArr;
  16.   range, lenCur, lenInit: integer;
  17. begin
  18.   lenCur := high(CurArr) ;  lenInit := high(InitArr) ;
  19.   range:= lenCur + lenInit +1;
  20.   SetLength(FinArr, range);
  21.   for i:= 0 to lenCur do
  22.     for j:= 0 to lenInit do
  23.       FinArr[i+j]:= FinArr[i+j] + CurArr[i]*InitArr[j];
  24.   Result:= FinArr;
  25. end;
  26.  
  27. function PolynomPower (CurArr:numArr; powN:integer):NumArr;
  28. var
  29.   i: integer;
  30.   StArr: NumArr;
  31. begin
  32.   SetLength(StArr,1);StArr[0] := 1;
  33.   for i:= 1 to PowN do
  34.     StArr := Multiply(StArr,CurArr);
  35.   Result:= StArr;
  36. end;
  37.  
  38. procedure printArray(TmpArr:NumArr);
  39. var i, tmp:integer;
  40.     OutputArrStr: string;
  41. begin
  42.   tmp:= high(TmpArr);
  43.   OutputArrStr:= OutputArrStr +  IntToStr(TmpArr[tmp]) + 'x^' + IntToStr(tmp);
  44.   for i:= tmp-1 downto 0 do begin
  45.     if sign(TmpArr[i]) = 1 then
  46.       OutputArrStr:= OutputArrStr + '+'+IntToStr(TmpArr[i]) +'x^' + IntToStr(i)
  47.     else if sign(TmpArr[i]) = 0 then
  48.       Continue
  49.     else
  50.       OutputArrStr:= OutputArrStr + '-' + IntToStr(abs(TmpArr[i])) + 'x^' + IntToStr(i);
  51.   end;
  52. Delete(OutputArrStr, Length(OutputArrStr)-2, 3);
  53.  
  54. Writeln(OutputArrStr)
  55. end;
  56. function SetArray():NumArr;
  57. begin
  58. end;
  59.  
  60. begin
  61.   write('Enter the number of members: ');readln(count);
  62.   SetLength(Numbers, count);
  63.  
  64.   for i:= count-1 downto 0 do begin
  65.   write('x^',i,': '); readln(Numbers[i]);    end;
  66.  
  67.   write('Enter Power: '); readln(powN);
  68.   Numbers := PolynomPower(Numbers, powN);
  69.   printArray(Numbers);
  70.   readln;
  71. end.
Add Comment
Please, Sign In to add comment