0% found this document useful (0 votes)
52 views4 pages

6.3 Exercises For Laboratory Work 6

The document provides exercises for working with two-dimensional arrays in C++. It includes 14 problems involving operations like finding sums, products, minimums, maximums of rows and columns of 2D arrays. It also provides 6 additional exercises, such as writing programs to transform one 2D array into another with different element values or inputting the array dimensions.
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)
52 views4 pages

6.3 Exercises For Laboratory Work 6

The document provides exercises for working with two-dimensional arrays in C++. It includes 14 problems involving operations like finding sums, products, minimums, maximums of rows and columns of 2D arrays. It also provides 6 additional exercises, such as writing programs to transform one 2D array into another with different element values or inputting the array dimensions.
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
You are on page 1/ 4

6.

3 Exercises for Laboratory Work 6

The topic of the laboratory work 6: Two-dimensional arrays. Tasks for each row
and for each column of a two-dimensional array.
The aim of the laboratory work 6: to write a program in C++ using two-dimensional
arrays, loop for; to input values of array elements of from the keyboard (or assign
values of array elements) and to display the results of the program on the screen.

Exercises:
Write a C++ program for solving this task with two-dimensional arrays.
1. Given an array A (5,5). Find the sum of negative odd elements and the greatest
element (maximum) of each row of two-dimensional array.
2. Given an array A (7,7). Find the product of even negative elements and the
greatest element (maximum) of each column of the two-dimensional array.
3. Given an array A (3,3). Find the minimum element and the greatest element
(maximum) of each row of two-dimensional array.
4. Given an array A (7,7). Find a product and the number of positive elements of
each column of the two-dimensional array.
5. Given an array A (4,4). Find the sum of even positive elements and the smallest
element (minimum) of each row of two-dimensional array.
6. Given an array A (8,8). Find the number of positive elements and the greatest
element (maximum) of each column two-dimensional array.
7. Given an array A (5,5). Find the sum of even negative elements and the greatest
element (maximum) of each column of two-dimensional array.
8. Given an array A (7,7). Find the number of negative elements and the greatest
element (maximum) of each column of two-dimensional array.
9. Given an array A (5,5). Find the minimum and the greatest element (maximum)
of each row of two-dimensional array.
10. Given an array A (7,7). Find the product and the number of negative elements of
each row of two-dimensional array.
11. Given an array A (4,4). Find the sum of even positive elements and the greatest
element (maximum) of each column of the dimensional array.
12. Given an array A (6,6). Find the product of positive elements and the greatest
element (maximum) of each row of the dimensional array.
13. Given an array A (4,4). Find the sum of odd elements and the greatest element
(maximum) of each column of two-dimensional array.
14. Given an array A (5,5). Find the product of even negative elements and the
greatest negative element of each column of the two-dimensional array.
15. Given an array A (3,3). Find the minimum even positive element and the greatest
negative element (maximum) of each row of two-dimensional array.
16. Given an array A (6,6). Find a sum and the number of positive elements of each
column of two-dimensional array.
17. Given an array A (5,5). Find the product of positive odd elements and the
smallest element (minimum) of each row of two-dimensional array.
18. Given an array A (8,8). Find the number of even negative elements and the
greatest element (maximum) of each row of two-dimensional array.
19. Given an array A (6,6). Find the product of odd negative elements and the
greatest element (maximum) of each column of two-dimensional array.
20. Given an array A (7,7). Find the number of odd negative elements and the
greatest element (maximum) of each column of two-dimensional array.

6.4Examples
Example 1.Given an array A (3,3). Find the number of even negative elements of
each column of two-dimensional array.
Solution:
#include<iostream>
#include<math.h>
using namespace std;

int main(){
int number;

int a[3][3]={{-8,-6, 8},


{ -4, -2, -7},
{ 3, -2, 9 }};

cout <<"Array:"<<endl;
// block to output elements of array a
for(int i=0; i<3; i++)
{
for(int j=0; j<3; j++)
{
cout << a[i][j]<< " ";
}
cout <<endl;
}
cout <<endl;

//block for each column of a matrix


for (int j = 0; j < 3; j++)
{number=0;
for (int i = 0; i< 3; i++)
{ if ((a[i][j]) <0 && (a[i][j]%2==0))
number =number+1 ;
}
cout <<"Number of "<<j<< " column= "<< number << " ";
cout <<endl;
}
}

Run the program and you will see on the screen of monitor:

Array:
-8 -6 8
-4 -2 -7
3 -2 9

Number of 0 column= 2
Number of 1 column= 3
Number of 2 column= 0

6.5 Additional exercises


Exercise 1.
Write a C++ program that forms a matrix B[10, 10], using loops, from a matrix
A[10,10].
A[10,10]: B[10, 10] :
1 1 1 1 1 2 2 2 2 2 4 4 4 4 4 3 3 3 3 3
1 1 1 1 1 2 2 2 2 2 4 4 4 4 4 3 3 3 3 3
1 1 1 1 1 2 2 2 2 2 4 4 4 4 4 3 3 3 3 3
1 1 1 1 1 2 2 2 2 2 4 4 4 4 4 3 3 3 3 3
1 1 1 1 1 2 2 2 2 2 4 4 4 4 4 3 3 3 3 3
3 3 3 3 3 4 4 4 4 4 2 2 2 2 2 1 1 1 1 1
3 3 3 3 3 4 4 4 4 4 2 2 2 2 2 1 1 1 1 1
3 3 3 3 3 4 4 4 4 4 2 2 2 2 2 1 1 1 1 1
3 3 3 3 3 4 4 4 4 4 2 2 2 2 2 1 1 1 1 1
3 3 3 3 3 4 4 4 4 4 2 2 2 2 2 1 1 1 1 1
3 3 3 3 3 4 4 4 4 4 2 2 2 2 2 1 1 1 1 1

Exercise 2.
Write a C++ program that forms a matrix B[5,5] from a matrix A[5,5], using loops.
A[5,5]: B[5,5]:
1 2 3 4 5 1 6 7 8 9
6 1 2 3 4 2 1 6 7 8
7 6 1 2 3 3 2 1 6 7
8 7 6 1 2 4 3 2 1 6
9 8 7 6 1 5 4 3 2 1

Exercise 3.
Write a C++ program that forms a matrix B[5,5] from a matrix A[5,5], using loops.
A[5,5]: B[5,5]:
1 2 3 4 5 9 8 7 6 5
2 3 4 5 6 8 7 6 5 4
3 4 5 6 7 7 6 5 4 3
4 5 6 7 8 6 5 4 3 2
5 6 7 8 9 5 4 3 2 1

Exercise 4.
Write a C++ program that forms a matrix A[5,5], using loops.

1 1 1 1 1
1 2 2 2 1
1 2 3 2 1
1 2 2 2 1
1 1 1 1 1

Exercise 5.
Write a C++ program that forms a matrix A, using loops, like in the Exercise 4, but
you must input any dimension from the keyboard.

Exercise 6.
Write a C++ program that forms a matrix A[5,5], using loops.

0 0 1 0 0
0 0 1 0 0
1 1 1 1 1
0 0 1 0 0
0 0 1 0 0

Exercise 7.
Write a C++ program that forms a matrix A[5,5], using loops.

1 0 1 0 1
0 1 1 1 0
1 1 1 1 1
0 1 1 0 1
1 0 1 0 1

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy