‫Hello my friends, and welcome to Coding Exercise number seven.
‫We are asked to write a program to count the number of even and odd elements in a given array of integers.
‫For example, this is the an array of integers five, seven, two, four and nine.
‫The odd now elements are five, seven, nine, and the even elements are two and four.
‫So the program will display for us a number of even elements is two, and the number of odd elements
‫is three.
‫So the goal of this exercise is to to to ensure that you understand the decision making and work with
‫arrays and the conditional statements.
‫So I want from you to pause the video, think about how to solve this problem and how to create a code
‫that accepts an array of integers and give the result of even and odd elements.
‫I am waiting your solutions in the comments below, so work on it.
‫Work on your IDE and please write the comment in the comments below your solution.
‫So I hope you are you solve it well and understand what's required.
‫I will create a var nums equal array of.
‫I will create the array of five.
‫3 to 6 and eight and one.
‫Okay.
‫This is an array of numbers that I want to check.
‫Okay.
‫Now.
‫I will create two counters.
‫Var
‫even underscore counter and equal to zero and var odd counter equal to zero.
‫I will start checking each element in this array even if it is an even its or odd.
‫Okay.
‫So I will check here.
‫Start for each loop.
‫For each I in nums check whether I.
‫If.
‫If nums at index.
‫Or if I modulo two.
‫Equal equal to zero, then it's even.
‫So increase the even counter by one the modulo.
‫Again you remembered the modulo will give you the remainder the value of the remainder of this division.
‫So if it is five over two will give you 0.5 as a remainder.
‫Okay.
‫Times two it will give you one.
‫So five modulo two will give you one.
‫Okay.
‫Because five contains two twos and only one will be remained.
‫So two times two plus one.
‫Actually five is equal to this.
‫Okay.
‫So this is a whole number, this integer, even integer, and this is the remainder.
‫Okay.
‫So it will give you one.
‫It will not increase the even counter.
‫It will increase the odd counter.
‫So odd counter plus plus.
‫Okay.
‫Then I need to display these counters print number.
‫Of even
‫even counter and
‫number of odd as odd.
‫Okay.
‫Okay, guys, this is very simple.
‫Okay, now let's run the program and see.
‫This is our array.
‫We have two, six and eight, three odd and three even.
‫And here we go.
‫Number of even three and number of odd is three.
‫Okay, so congratulations, guys.
‫We have solved it.
‫I hope you understand well and understand how the for loops and the decision making and the conditional
‫statements works and how this algorithm works.