Array Programming

You might also like

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 3

Programming based on Arrays :

1. write a program to find the number of even integers and odd integers in a given
array in c++ language

a)
#include<iostream.h>
#include<conio.h>
Void main()
{
int a[5],count_even=0,count_odd=0,i;

for(i=0;i<5;i++)
cin<<&a[i];
/* display the number of odd and even intergers */
for(i=0;i<5;i++)
{
if((a[i]%2 ==0))
cout<<count_even++;
if((a[i]%2==1))
cout<<count_odd++;
}
Cout<<count_even<<count_odd”;
getch();
}
 
b)
#include<iostream.h>
#include<conio.h>
void main()
{
int a[10],even=0,odd=0,i;
for(i=0;i<9;i++)
{
if(a[i]%2==0)
{
Cout<<”\ta[i]”;
even++;
}
else
{
Cout<<”\ta[i]”;
odd++;
}
}
Cout<<"Total no of Even found is="<<even;
Cout<<”Total no of Odd found is=”<<odd;
getch();
}
 

You might also like