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!