LAST UPDATED: APRIL 18, 2022
C++ Program To Find Row In An Array That Includes The Greatest Amount Of Even Number
In this tutorial we will that how we can find the row that contains the maximum number of even number with comparisons to the other rows in the array or we can say a 2-D array.
Find Row In An Array That Includes The Greatest Amount Of Even Number In C++
Before proceeding with the implementation part let's have a look on one example what actually is the problem statement.
Let A= 8 9 3
7 2 4
6 1 9
then output will be the second row as it contains maximum number od even numbers i.e. (2 and 4) two even numbers whereas the other rows contain only one even number.
#include<iostream>
using namespace std;
int main()
{
int a[10][10],n,l,i,j,count=0;
cout<<"\nEnter The Matrix Size (l*l)\n";
cin>>l;
cout<<"\nEnter The Row Number Of Matrix\n";
cin>>n;
if(n<0||n<=l)
{
}
else
{
cout<<"\nRow Is Exceed The Limit Enter Value >0 And Less Than Size Of Matrix \n";
exit(0);
}
cout<<"Enter The Matrix Value\n";
for(i=1;i<=l;i++)
for(j=1;j<=l;j++)
cin>>a[i][j];
cout<<"\n\nMatrix Row Is Given Below\n\n";
for(i=1;i<=l;i++)
{
cout<<a[n][i]<<" ";
if(a[n][i]%2==0)
count++;
}
cout<<"\n\nNo. Of Even Number In Row IS = "<<count;
return 0;
}
Enter The Matrix Size (l*l)
3
Enter The Row Number Of Matrix
2
Enter The Matrix Value
7 8 9 1 2 3 4 5 6
Matrix Row Is Given Below
1 2 3
No. Of Even Number In Row IS = 1
Conclusion
Here, we have seen how to implement a C++ program to Find Row In An Array That Includes The Greatest Amount Of Even Number.