Program To Check Each Element of a 1-D Integer Array For Evenness / Oddness. Means you have to find even and odd number in an array.
Explanation:-
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 an array if number divide by 2 and reminder 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;
}
Output:
Enter The Size of Array
6
Enter The Element
1
2
3
4
5
6
Elment in Array is Given Below
Evenness
1 Oddness
2 Evenness
3 Oddness
4 Evenness
5 Oddness
6
need an explanation for this answer? contact us directly to get an explanation for this answer