use function for and if via matlap

조회 수: 3 (최근 30일)
Musaed
Musaed 2023년 5월 6일
답변: Musaed 2023년 5월 6일
50 60 -2 -15 100
1- find the sum of a set of five different numbers
2- find the sum of negative numbers
3-find how many numbers are more than 40 and less than 90
  댓글 수: 1
Image Analyst
Image Analyst 2023년 5월 6일
To learn such very fundamental concepts, invest 2 hours of your time here:

댓글을 달려면 로그인하십시오.

채택된 답변

Atsushi Ueno
Atsushi Ueno 2023년 5월 6일
nms = [50 60 -2 -15 100];
sum(nms) % 1- find the sum of a set of five different numbers
ans = 193
sum(nms(nms < 0)) % 2- find the sum of negative numbers
ans = -17
sum(nms > 40 & nms < 90) % 3-find how many numbers are more than 40 and less than 90
ans = 2

추가 답변 (1개)

Musaed
Musaed 2023년 5월 6일
%[50 60 -2 -15 100]
sum=0;
for x=1:5
z=input('enter#')
sum=sum+z;
end
disp('sum=')
disp(sum)

카테고리

Help CenterFile Exchange에서 Numerical Integration and Differential Equations에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by