Are two numbers divisible? Write a function called checkFactor that takes two ar
ID: 3588446 • Letter: A
Question
Are two numbers divisible? Write a function called checkFactor that takes two arrays of positive numbers, firstNumberRow and secondNumberRow, and checks if the first entry in firstNumberRow is divisible by the first entry in secondNumberRow, and performs the same operation on the next array elements, untill all entries have been checked. You may assume that all the numbers are positive and the number of entries in the arrays is the same. The function should return the identified divisible numbers in two row arrays firstDivisible and secondDivisible. Restriction You may not use branches or loops. For example,if firstNumberRow[5, 7, 8, 8, 3]; secondNumberRow = [7, 7, 2, 2, 5); [firstDivisible,secondDivisible]-checkFactor(firstNumberRow, secondNumberRow) produces firstDivisible = 7 8 secondDivisible = 7 2 2 Indicating that the second entries (the two 7s), the third entries (the 8 and the 2), and finally the fourt entries (the 8 and 2) are divisible positive integers Your Function Save Reset MATLAB Documentation 1 function [firstDivisible,secondDivisible]-checkFactor(firstNumberRow, secondNumberRow) % Your code goes here % 6 end Code to call your function C Reset 1 [firstDivisible,secondDivisible]-checkFactor(firstNumberRow, secondNumberRow)Explanation / Answer
Matlab Function:
function [firstDivisible, secondDivisible] = checkFactor(firstNumberRow, secondNumberRow)
%empty arrays
firstDivisible = [];
secondDivisible = [];
%iterate through arrays
for i = 1:numel(firstNumberRow)
%if divisible add elements to corresponding arrays
if(mod(firstNumberRow(i),secondNumberRow(i)) == 0)
firstDivisible = [firstDivisible, firstNumberRow(i)];
secondDivisible = [secondDivisible, secondNumberRow(i)];
end
end
end
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.