ورود

View Full Version : Write a function called rich



CYLONS
جمعه 19 تیر 1394, 17:43 عصر
خسته نباشید.

Suppose we have a pile of coins. Write a function called rich that computes how much money we have. It takes one input argument that is a row vector whose 4 elements specify the number of pennies (1 cent), nickels (5 cents), dimes (10 cents), and quarters (25 cents) that we have (in the order listed here). The output of the function is the value of the total in dollars (not cents). For example, if we had five coins, four quarters and a penny, the answer would be 1.01


فرض کنید تعدادی سکه داریم. تابعی با نام rich بنویسید که پول ما را محاسبه کند. این تابع دارای یک ورودی به صورت بردار چهارسطری است که چهار عنصر آن: پنی (1 سنت)، نیکل (5 سنت)، دیم (10 سنت) و کوارتر (25 سنت) می باشد. خروجی تابع کل پول "بر حسب دلار" می‌باشد. برای مثال اگر 5 سکه داشته باشیم، برابر چهار کوارتر و یک پنی است و پاسخ 1.01 دلار می‌شود.

ممنون اگه جواب بدید.

rahnema1
جمعه 19 تیر 1394, 18:00 عصر
function result = rich(coins)
result = sum(coins .* [1 5 10 25]) / 100;
end