Construct the statement on MATLAB: If a person has more than 10 apples then he will sell 8. But if he has less than 10 apples than he will sell 5 apples
1 次查看(过去 30 天)
显示 更早的评论
Construct the statement on MATLAB: If a person has more than 10 apples then he will sell 8. But if he has less than 10 apples than he will sell 5 apples.
0 个评论
回答(1 个)
Wan Ji
2021-8-21
apples_left = 20; % total apples at the beginning
while true
if(apples_left<5)
break;
end
if(apples_left>10)
apples_sold = 8;
elseif(apples_left<=10)
apples_sold = 5;
end
apples_left = apples_left - apples_sold;
fprintf('apples_sold = %d, apples_left=%d\n', apples_sold, apples_left)
end
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!