C++ | Finding Even numbers from arrays

Join Programming and Development Chat Groups on Uphub.io

Introduction

This tutorial of c++ will show you to create a program of finding even numbers from arrays. The program below is given. The program is not extendable. Go enjoy the program. Lets begin………

Program to find the even numbers from array


#include<iostream.h>
#include<conio.h>
void main()
{
//clear the screen.
clrscr();
//declare variable type int
int a[10],i,x;
//Input the two numbers save them in arrays.
//Here for loop is used to input multiple numbers in array.
for(i=0;i<5;i++)
{
cout<<"Enter the no."<<endl;
cin>>a[i];
}
//cout
cout<<"Even numbers are ";
//show the output arrays
for(i=0;i<5;i++)
{
x=a[i]%2;
if(x==0)
cout<<a[i]<<" ";
}
//get character
getch();
}

Output

Enter the no.
1
Enter the no.
2
Enter the no.
3
Enter the no.
4
Enter the no.
5
Even numbers are 2 4

How does it work

  1. You enter the number.
  2. The number is saved in respective array.
  3. The numbers from arrays are taken and tested if even or odd.
  4. The even number is printed.

Extending it

The program cannot be extended.

Explanation.

  1. Include ‘iostream.h’ and ‘conio.h’ files.
  2. Add void main.
  3. Start program by first clearing the screen.
  4. Declare the variables as int (name them as you want.)
  5. Add the cout and cin of array.
  6. Find the mod of number and 2.
  7. If zero print the number.

At the end

You learnt creating the C++ program of Finding even numbers in array. So now enjoy the program.

Please comment on the post and share it.
And like it if you liked.

Sharing options: