function a = r8mat_diagonal ( n, diag )

%*****************************************************************************80
%
%% r8mat_diagonal() returns a diagonal matrix as an R8MAT.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    02 August 2018
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer N, the order of A.
%
%    real DIAG(N), the diagonal entries.
%
%  Output:
%
%    real A(N,N), an NxN matrix with given diagonal entries.
%
  a = zeros(n,n);

  for i = 1 : n
    a(i,i) = diag(i);
  end

  return
end
