Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Now it\'s Your turn, again. Write a function (reverse sentence. m) that takes a

ID: 3819395 • Letter: N

Question

Now it's Your turn, again. Write a function (reverse sentence. m) that takes a single input argument which is a string containing a sentence (a sequence of words) and returns a single output argument which is a string containing the words in the input string in reverse order. For example, on input ' the quick brown fox jumps over the lazy dog', the function should return ' dog lazy the over jumps fox brown quick the'. Remember to think before you code. Have pencil and paper next to you and sketch your algorithm as pseudocode or flow diagram. I will get you started on this one: Split the sentence at whitespace to form an array of words. Reverse the array of words. Construct the reversed sentence by joining the words in the array with spaces.

Explanation / Answer

%matlab code

function reverse = reverse_sentence(input)
array = strsplit(input);
reverse = '';
for i=1:length(array)
reverse = strcat(reverse, array(length(array)-i+1), ' ');
  
end
end

input = 'the quick browns fox jumps over the lazy dog';
reverse = reverse_sentence(input)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote