Write a program that will let the user input 15 numbers (3x5) array.
Print the even numbers in the 2nd
row.
Code:
#include<iostream>
using namespace std;
int main()
{
int a[3][5],i,x;
cout<<"Enter 15 numbers:";
for(x=0;x<3;x++)
{
for(i=0;i<5;i++)
{
cin>>a[x][i];
}
}
cout<<"Even numbers in the 2nd row are:\n";
for(x=0;x<3;x++)
{
for(i=0;i<5;i++)
{
if(x==1 && a[x][i]%2==0)
{
cout<<a[x][i]<<"\t";
}
}
}
}
Let the user input 12 numbers (4x3) array and a row index. Print how many are positive and negative
numbers in the chosen row.
Code:
#include<iostream>
using namespace std;
int main()
{
int a[4][3],i,x,pos=0,neg=0,ri;
cout<<"Enter 12 numbers:";
for(x=0;x<4;x++)
{
for(i=0;i<3;i++)
{
cin>>a[x][i];
}
}
cout<<"Enter row index (0-3): ";
cin>>ri;
for(x=0;x<4;x++)
{
for(i=0;i<3;i++)
{
if(x==ri && a[x][i]>0)
{
pos++;
}
if(x==ri && a[x][i]<0)
{
neg++;
}
}
}
cout<<"Positive: "<<pos;
cout<<"\n Negative: "<<neg;
}