C++ program to calculate no. of even and odd numbers in a given array.


If you want to run this program for more then five no.,then you have to modify A[5] and i<5.
C++ code for array of five numbers.

#include <iostream.h> void main() { int A[5],n=0,m=0; cout<<"Enter numbers : "; for(int i=0;i<5;i++) { cin>>A[i]; if(A[i]%2==0) n++; else m++; } cout<<"\nNo. of odd numbers = "<<m; cout<<"\nNo. of even numbers = "<<n; }

OUTPUT-

Enter numbers : 6 2 3 4 5 no. of odd numbers =2 no. of even numbers =3

Comments :

Post a Comment