0% found this document useful (0 votes)
42 views3 pages

Array Programming

The document provides two C++ code examples for counting the number of even and odd integers in an array. The first example uses a for loop to iterate through the array, checks each element for divisibility by 2, and increments the even and odd counter variables accordingly. It then prints the final even and odd count values. The second example also uses a for loop to iterate the array, checks elements for divisibility, and prints each even/odd element while incrementing the respective counter variables. It concludes by printing the total even and odd counts.

Uploaded by

Rahul Sarangle
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views3 pages

Array Programming

The document provides two C++ code examples for counting the number of even and odd integers in an array. The first example uses a for loop to iterate through the array, checks each element for divisibility by 2, and increments the even and odd counter variables accordingly. It then prints the final even and odd count values. The second example also uses a for loop to iterate the array, checks elements for divisibility, and prints each even/odd element while incrementing the respective counter variables. It concludes by printing the total even and odd counts.

Uploaded by

Rahul Sarangle
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 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