count even numbers of a matrix
13 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Found how many even numbers are present in a 3×3 matrix. And find the value of multiple of those even numbers.
1 Commento
Rik
il 29 Dic 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")?
Risposte (2)
Rik
il 28 Dic 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 Commenti
Image Analyst
il 28 Dic 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 Commenti
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!