Calculating the sum of A elements which are numbers between 30 and 65
5 views (last 30 days)
Show older comments
Commented: Karem Kassem on 7 Nov 2019
Hey, i need help with school assignment, i have created an array of 8 rows and 20 columns whose elements are random numbers between 10 and 100:
i have to find the elements in A which are between 30 and 65! and Calculate the sum of these numbers.
this is what i got so far:
if A(i,j)>30 & A(i,j)<65
And this only shows the first if argument, and the sum is 401 which i think is the sum if hiw many numbers are greater than 30.
Now my teacher says we have to use this format which i dont understand why:
David Hill on 7 Nov 2019
You had it!
if A(i,j)>30 && A(i,j)<65
B=B+A(i,j);%B is the sum of all elements of A between 30 and 65
More Answers (1)
jannat alsaidi on 7 Nov 2019
No need to initiate two values s and N, only one for accumulator.
Find more on Matrices and Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!