Question: Write a code which for a given one - dimensional array A ( vector ) looks for pairs ( p , q ) such that

Write a code which for a given one-dimensional array A (vector) looks for pairs (p, q) such that A(p)*A(q) is an even number. That is, the code should return
- a numeric variable telling what is the number of pairs (say nn)
- an array listing the pairs of indices (the size of the array should be n2n2.
The code should return n=1n=1 as the number of pairs, and an empty array of indices if the number of pairs exceeds 109109.
For example, given an array A =[215-5] the code should return number of pairs as 3, and then an array [1,2; 1,3; 1,4], becausethere are exactly three pairs that full the above conditions, namely:
(1,2), because A(1)*A(2)=2,
(1,3), because A(1)*A(3)=10,
(1,4), because A(1)*A(4)=-10.
Note that pairs should not be double-counted, because (1,4) and (4,1) is treated as the same pair. Answer in matlab code please.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!