count even numbers of a matrix
9 views (last 30 days)
Show older comments
Found how many even numbers are present in a 3×3 matrix. And find the value of multiple of those even numbers.
1 Comment
Rik
on 29 Dec 2021
Why did you remove your comment ("n=3; A=magic(n) for i=1:n*n for p=A(i) if rem(p,2)==0 p; end end end i tried this. but could not find the proper answer")?
Answers (2)
Rik
on 28 Dec 2021
This sounds a lot like homework. What did you try? I think you will be able to do it yourself if you read the documentation for the mod function.
0 Comments
Image Analyst
on 28 Dec 2021
No double for loop needed. Try this:
n=3;
A=magic(n)
remainders = rem(A, 2) == 0
then use sum() to count the 1's.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!