Signup/Sign In
PUBLISHED ON: APRIL 19, 2022

C++ Program To Check Evenness / Oddness Of An Array

In this tutorial, we will write a program To Check Each Element of a 1-D Integer Array For Evenness / Oddness. This means we have to find even and odd numbers in an array.

Program To Check Evenness / Oddness Of An Array In C++

If the number is divided by 2 then the number is an even number if not the number is odd. So we divide the number of an array one by one of the array if the number is divided by 2 and the remainder is zero then the number is even and if the remainder is not zero then the number is odd.

#include<iostream>
using namespace std;
int main()
{
  int a[100],i,n,sum=0;
  
 cout<<"Enter The Size of Array\n";
  cin>>n;

  cout<<"Enter The Element\n";
  for(i=0;i<n;i++)
  {
   cin>>a[i];
  }
  cout<<"Elment in Array is Given Below\n";
  for(i=0;i<n;i++)
  {
   if(i%2==0)
   cout<<"Evenness  \n"<<a[i]<<"  ";
   else
   cout<<"Oddness  \n"<<a[i]<<"  ";
  }
 return 0;

}


Enter The Size of Array
5
Enter The Element
1 8 6 3 24
Elment in Array is Given Below
Evenness
1 Oddness
8 Evenness
6 Oddness
3 Evenness
24

Conclusion

In this tutorial, we have seen how to implement a C++ Program To Check the Evenness / Oddness Of An Array.



About the author:
Nikita Pandey is a talented author and expert in programming languages such as C, C++, and Java. Her writing is informative, engaging, and offers practical insights and tips for programmers at all levels.