Answer to Question #315062 in C++ for Secret Agent

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
1
Expert's answer
2022-03-21T08:22:50-0400
#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;	  
    }	
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog