Wednesday, February 13, 2013

Even and Odd - Simple Even/Odd program - Write a Even and Odd program - Check Even and Odd Number

Write a program in C++ Even or Odd:


#include<iostream.h>
void main()
{
int I=1;
cout<<"Even numbers between 1 and 20n";
do{
if(I%2==0)
cout<<I<<"n";
I++;
}while(I<=20) ;
}

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

#include<studio.h>
#include<conio.h>
main()
{
  int a[5], even=0, odd=0,i;

   for(i=0;i<5;i++)

       scanf("%d",&a[i]);
/* display the number of odd and even intergers */
for(i=0;i<5;i++)
{
   if((a[i]%2 ==0))
          even++;
    if((a[i]%2==1))
          odd++;
}
printf("%d /n %d", even,odd);
getch();
}

0 comments:

Post a Comment