function a = change_greedy ( value, target )

%*****************************************************************************80
%
%% change_greedy() solves the change making problem using a greedy algorithm.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    30 June 2017
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer VALUE(COIN_NUM), the value of each coin.
%
%    integer TARGET, the desired sum.
%
%  Output:
%
%    integer A(COIN_NUM): the number of each coin used by the greedy method.
%
  coin_num = length ( value );
%
%  Descending sort the coin values.
%
  [ value_sorted, index_sorted ] = sort ( value, 'descend' );

  for i = 1 : coin_num
    coin = index_sorted(i);
    a(coin) = floor ( target / value(coin) );
    target = target - a(coin) * value(coin);
  end

  return
end
 
