Sunday, 22 January 2017

To count no. of even and odd elements in an Array

#include<conio.h>
#include<iostream.h>
# define r 10
void main()
{ clrscr();
  int a[r];
  int b=0,c=0;
  for (int i=0;i<r;i++)
      { cin>>a[i];
if(a[i]%2==0)
 { b++;
 }
else { c++;
    }
      }
  cout<<"Number of odd elements = "<<c<<"\n";
  cout<<"Number of even elements = "<<b;
  getch();
}

No comments:

Post a Comment

Basic Implementation of Array as a Pointer

#include<iostream.h> #include<conio.h> void main() { clrscr();   int arr[5];   cout<<"Enter 5 nos. ";   f...