Saturday, 31 October 2015

C++ Program To Check Evenness And Oddness In An Array

Problem :- Program To Check Each Element of a 1-D Integer  Array For Evenness / Oddness .Means you have to find even and odd number in a array .

Logic :- If number is divide by 2 then number is even number if not then number is odd check here C++ Program To Find Number Is Even Or Odd Using Pointer then proceed for array .

Solution :-

#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;

}

Output:-

C++ Program To Check Evenness And Oddness In An Array

No comments:
Write comments

Recommended Posts × +