function r = polynomial_multiply ( p, q )

%*****************************************************************************80
%
%% polynomial_multiply() multiplies two polynomials.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    22 October 2022
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    real p(*), q(*): all the coefficients of two polynomials, zero or nonzero.
%
%  Output:
%
%    real r(*): all the coefficients of the product polynomial.
%
  pn = length ( p );
  while ( p(pn) == 0 && 1 < pn )
    pn = pn - 1;
  end

  qn = length ( q );
  while ( q(qn) == 0 && 1 < qn )
    qn = qn - 1;
  end

  rn = qn + pn;
  r = zeros ( 1, rn );
  for i = 1 : pn
    for j = 1 : qn
      k = i + j - 1;
      if ( k <= rn )
        r(k) = r(k) + p(i) * q(j);
      end
    end
  end

  return
end

