4
4
4cesc42016-04-10 15:53:23
Arrays
4cesc4, 2016-04-10 15:53:23

How to display only even numbers from an array of numbers?

Create an array of numbers 12, 42, 63, 56, 122, 17, 117, 25, 645, 722, 964 and display only even numbers from this array to the console.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
W
Wernalur, 2016-04-10
@Wernalur

var arr = [12, 42, 63, 56, 122, 17, 117, 25, 645, 722, 964];

for (var i = 0; i < arr.length; i++)
{
  if ((arr[i] % 2) === 0)
  {
  	console.log(arr[i]);
  }
}

I
idsoslanpuhaev, 2017-04-30
@idsoslanpuhaev

c#
int[] a = {2, 4 , 25 ,50};
int c;
for(int i=0; i<=a.Lenght; i++){
if( (a [i] % 2)==0 ) {
c=a[i];
Console Writeline(c);
}
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question