Question #315062

 Only the Even Ones

by CodeChum Admin

I have an array of 3 numbers here with me that's already in the code editor, but I want you to add some more to this list by inputting some more numbers yourself in one line and then, print out only the even numbers from the array.


Can you do that for me?


Input

The first line contains the number of elements, n, to be added.

The next line contains the n integers separated by a space.

5
33·54·32·11·8

Output

Multiple lines containing an integer.

2
54
32
8

Expert's answer

#include<iostream>
using namespace std;
int main(int argc, char *argv[])
{
   int num;	
   cout<<"Please, enter the number of elements:"; 
   cin>>num;
   int *arr= new int[num];	
   cout<<"Please, enter "<<num<<" elements:";
   for(int i=0;i<num;i++)	
   {	
    cin>>arr[i];	
   }	
   for(int i=0;i<num;i++)	 
   {		    
     if(arr[i]%2==0)		   
       cout<<arr[i]<<endl;	  
    }	
}
LATEST TUTORIALS
APPROVED BY CLIENTS