Seperating evens and odds
10 次查看(过去 30 天)
显示 更早的评论
What would be the method to solve the problem below
Generate a vector of 20 random integers, each in the range of 50 to 100 and store it in vec. Create a variable evens that stores all of the even numbers from the vector, and a variable odds that stores all of the odd numbers.
1 个评论
Korede Akinpelumi
2017-5-16
编辑:Walter Roberson
2017-5-16
function [evens,odds]=assignm
A=randi(51,1,20)+49;
B=50:2:100;
C=51:2:99;
evens=intersect(A,B);
odds=intersect(A,C);
end
回答(2 个)
Walter Roberson
2015-9-15
x == 2 * floor(x/2)
is true for even numbers and false for everything else
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!