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

조회 수: 1 (최근 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에서 Web Services에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by