Odd and even numbers

Technical Source
2 min readAug 18, 2023

--

Hi

I’m new in matlab so i need a little help to get started. How do i make a program which can distinguish from odd and even numbers? I know that i need to make a loop, it should be either if or while but i would love some suggestions on how to solve this problem.

NOTE:-

Matlabsolutions.com provide latest MatLab Homework Help,MatLab Assignment Help , Finance Assignment Help for students, engineers and researchers in Multiple Branches like ECE, EEE, CSE, Mechanical, Civil with 100% output.Matlab Code for B.E, B.Tech,M.E,M.Tech, Ph.D. Scholars with 100% privacy guaranteed. Get MATLAB projects with source code for your learning and research.

You simply have to go back to the definition of odd and even. An (integer) number is even if it is divisible by 2, odd otherwise. Divisible by 2 means that the remainder when divided by 2 is 0. That is easy to test, the function to get the remainder is (or you can use ). As with many things in matlab you do not need a loop, the functions work on vector / matrices

m = [1 2 3;4 5 6]; 
iseven = rem(m, 2) == 0;

Mathworks Support Staff Comments

Depending on the usage, you can use “rem” or “mod” to check if a number is divisible by 2. The “r = rem(a,b)” function finds the remainder after division of a by b, where the sign of the remainder r follows the sign of a. Meanwhile, the “r = mod(a,b)” function finds the remainder after division of a by b, where the sign of the remainder r follows the sign of b.

For example, if you have a matrix of integer numbers that are positive only, you can find the even or odd numbers by first finding the matrix indices of these elements using “rem”:

SEE COMPLETE ANSWER CLICK THE LINK

--

--

Technical Source

Simple! That is me, a simple person. I am passionate about knowledge and reading. That’s why I have decided to write and share a bit of my life and thoughts to.