Write a function named pluralize that takes 2 arguments: a noun and a number. Th
ID: 3827460 • Letter: W
Question
Write a function named pluralize that takes 2 arguments: a noun and a number. Then, it returns the number and the pluralized form, like "5 cats" or "1 dog". Pay attention to the 's' you need to include for the plural form. Do not take into consideration countability/uncountability. Just Assume if it is plural, you need include an 's'. Finally, if the number is less than or equal to zero, your program should return invalid Number'. Example: 1) pluralize ('Cat', 5) rightarrow 5 Cats 2) pluralize ('Sugar', 1) rightarrow 1 Sugar
Explanation / Answer
function s = pluralize(s, n)
if n <= 0
s = "Invalid Number";
return;
elseif n == 1
s = [num2str(n), ' ', s];
return;
else
s = [num2str(n), ' ', s, 's'];
end
end
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.