Write a Matlab function named pluralize that takes 2 arguments: a noun and a umb
ID: 3827745 • Letter: W
Question
Write a Matlab function named pluralize that takes 2 arguments: a noun and a umber. 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')-> 5 Cats
2) pluralize ('Sugar,1')->1 Sugar
Explanation / Answer
here is matlab function
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
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.