3. Using a for-loop, identify how close two words are by incorporating a for-loo
ID: 3699793 • Letter: 3
Question
3. Using a for-loop, identify how close two words are by incorporating a for-loop using the following algorithm: 1. First determine whether or not the two words are the same length 2. If the words are different lengths, then output the difference of the two lengths and exit. If the words are the same length, then step through the letters of each word using a for-loop and identify the number of characters that are mismatched. For example, the words bat and bag have 1 mismatch whereas bag and bag have 0 mismatches. Output the two words and the number of mismatches. 3.Explanation / Answer
a = "bat";
b = "bag";
count = 0;
if length(a) == length(b)
for i = 1:length(a);
if a(i) != b(i)
count++;
end
end
else
disp("Different length")
end
count
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.