Program that separates even and odd numbers and shows them in two vectors.
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Dionisio Mendoza
am 4 Feb. 2019
Beantwortet: Andrei Bobrov
am 4 Feb. 2019
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.
0 Kommentare
Akzeptierte Antwort
Andrei Bobrov
am 4 Feb. 2019
n = (1:100)';
lo = rem(n,2)==1;
pares = n(~lo);
impares = n(lo);
0 Kommentare
Weitere Antworten (1)
KSSV
am 4 Feb. 2019
A = magic(5) ;
A = A(:) ;
idx = mod(A,2)==0 ;
E = A(idx) ; % Even numbers
O = A(~idx) ; % Odd numbers
Siehe auch
Kategorien
Mehr zu Web Services finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!