Program that separates even and odd numbers and shows them in two vectors.

3 次查看(过去 30 天)
The program must throw 100 in two vectors, in one the 50 pairs will be shown and in the other 50 odd. All this using the cilco for and conditions if they are necessary. I already got him to throw the numbers but to separate them.

采纳的回答

Andrei Bobrov
Andrei Bobrov 2019-2-4
n = (1:100)';
lo = rem(n,2)==1;
pares = n(~lo);
impares = n(lo);

更多回答(1 个)

KSSV
KSSV 2019-2-4
A = magic(5) ;
A = A(:) ;
idx = mod(A,2)==0 ;
E = A(idx) ; % Even numbers
O = A(~idx) ; % Odd numbers

类别

Help CenterFile Exchange 中查找有关 Fourier Analysis and Filtering 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by