% hypot.m
%
% CS 221 HW 2
% Part 2, Problem 3

% Write a MATLAB function hypot() that takes two arguments: arrays A
% and B (both must have the same number of arguments), and returns an
% array C, containing the length of the hypoteneuse for each triangle.

function C = hypot(A,B)

  % Since the problem specifies that A and B must
  % have the same number of elements, this line is optional.
  array_length = min(length(A), length(B));

  % You can either add elements to C one-by-one, or initialize C to 
  % be the correct size and contain zeroes using the zeros() function.
  C = zeros(1, array_length);  

  % Use a for-loop to iterate over the two arrays and compute the 
  % values in C. 
  % Here we use the variable "k" to index all arrays A, B, and C.
  % This is one of many ways to 
  for k = 1:array_length
    C(k) = sqrt(A(k)^2 + B(k)^2);
  end

end

  
% Save the function in a file hypot.m. 

% Since MATLAB has a built-in function called "hypot" we will also
% accept files/functions with some similar name such as hypot1.m.

