Â
In this, we are going to print the even numbers present in the array element in  C++.
The code given below can be used for TURBO C++ Compiler:-
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int b[5],i,j;
// Taking array elements as inputb[0] = b[i];
cout<<"Enter array elements \n";
for(i=0;i<5;i++){
cin>>b[i];
}
for (int i = 0; i<5; ++i)
{
if (b[i] % 2 == 0)
{
cout<<b[i]<<" is an even number\n";
}
else
{
cout<<b[i]<<" is an odd number\n";
}
}
getch();
}
The code given below can be used for g++/gcc Compiler:-
#include<iostream>
using namespace std;
int main()
{
int b[5],i,j;
// Taking array elements as inputb[0] = b[i];
cout<<"Enter array elements \n";
for(i=0;i<5;i++){
cin>>b[i];
}
for (int i = 0; i<5; ++i)
{
if (b[i] % 2 == 0)
{
cout<<b[i]<<" is an even number\n";
}
else
{
cout<<b[i]<<" is an odd number\n";
}
}
return 0;
}
#ENJOY CODING
Post a Comment
FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP