0% found this document useful (0 votes)
12 views2 pages

2D Array Problems W Code

The document contains two C++ programs. The first program allows the user to input 15 numbers into a 3x5 array and prints the even numbers from the second row. The second program prompts the user to input 12 numbers into a 4x3 array and a row index, then counts and displays the number of positive and negative numbers in the specified row.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views2 pages

2D Array Problems W Code

The document contains two C++ programs. The first program allows the user to input 15 numbers into a 3x5 array and prints the even numbers from the second row. The second program prompts the user to input 12 numbers into a 4x3 array and a row index, then counts and displays the number of positive and negative numbers in the specified row.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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;
}

You might also like