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

7 1

The document contains code for a C++ program that generates random or user-inputted 2D arrays, sums the columns, sorts the columns in ascending order while also sorting the corresponding rows of the 2D array, and outputs the results. The program allows the user to generate the random array or enter the values themselves and also contains options to rerun or exit the program.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views4 pages

7 1

The document contains code for a C++ program that generates random or user-inputted 2D arrays, sums the columns, sorts the columns in ascending order while also sorting the corresponding rows of the 2D array, and outputs the results. The program allows the user to generate the random array or enter the values themselves and also contains options to rerun or exit the program.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

#include<iostream>

#include<stdlib.h>
#include<time.h>
#include<conio.h>
#include <locale>
#include <iomanip>

using namespace std;


int m, n, i, l=0;
int a[10][10];
int b[10];
int sum;

//������� ������ ��������

void inputr()
{
setlocale(LC_ALL, "Ukrainian");
srand((unsigned)(time(NULL)));
cout << "����i�� �i���i��� ���i� (<=10)" << endl;
cin >> m;
while (m < 3 || m > 10)
{
cout << "m>=3 � m<=10" << endl;
cin >> m;
}
cout << "����i�� �i���i��� ������i� (<=10)" << endl;
cin >> n;
while (n < 3 || n > 10)
{
cout << "n>=3 � n<=10" << endl;
cin >> n;
}

for (int i = 0; i < m; i++)


{
for (int j = 0; j < n; j++)
{
a[i][j] = rand() %200-100;
}
}
cout << "����������� ������: " << endl;

//������� ������ � ���������

void inputk()
{
setlocale(LC_ALL, "Ukrainian");
cout << "����i�� �i���i��� ���i� (<=10)" << endl;
cin >> m;
while (m < 3 || m > 10)
{
cout << "m>=3 � m<=10" << endl;
cin >> m;
}
cout << "����i�� �i���i��� ������i� (<=10)" << endl;
cin >> n;
while (n < 3 || n > 10)
{
cout << "n>=3 � n<=10" << endl;
cin >> n;
}

for (int i = 0; i < m; i++)


{
for (int j = 0; j < n; j++)
{
cout << "massiv[" << i << "][" << j << "] = ";
cin >> a[i][j];
}
}
cout << "����������� ������: " << endl;

//�������� ������

void output()
{
for (int i = 0; i < m; i++)
{
for (int j = 0; j < n; j++)
{
cout << setw(5) << a[i][j] << " ";
}
cout << "\n";
}
}

//����� ����

void arr2()
{
setlocale(LC_ALL, "Ukrainian");
cout << "���� �� �������: " << endl;
for (int j = 0; j < n; j++)
{
sum = 0;
for (int i = 0; i < m; i++)
{

sum += a[i][j];

b[l++] = sum;

//�������� ������ ����

void output2()
{
for (int i = 0; i < n; i++)
{
cout << setw(5) << b[i] << " ";
}
}

//��������� ������

void sort()
{

int temp, temp2;

for (int i = 0; i < n-1 ; i++)


{
for (int j = 0; j < n - i-1; j++)
{
if (b[j] > b[j + 1])
{

temp = b[j];
b[j] = b[j + 1];
b[j + 1] = temp;
for (int i = 0; i < m; i++)
{
temp2 = a[i][j];
a[i][j] = a[i][j + 1];
a[i][j + 1] = temp2;
}
}

// ����� ���������������� ������� �� �����


cout << endl;
cout << "������������ ����� � ���i����� ������: " << endl;
output();
cout << endl;
cout << "�i����������� ����� ���" << endl;
output2();
cout << endl;
}

int main()
{
setlocale(LC_ALL, "Ukrainian");
int e, p, v;
cout << "1.����������� ����� ��������" << endl;
cout << "2.����������� ����� � ����i�����" << endl;
cin >> e;
switch (e)
{
case 1:
inputr();
break;
case 2:
inputk();
break;
}

output();
arr2();
output2();
cout << endl;
sort();
cout << endl;
cout << "������ ����������?(1 ���/ 2 �i)";
cout << endl;
cin >> p;
while (p != 1 && p != 2)
{
cout << "1 ���/ 2 �i" << endl;
cin >> p;
}
switch (p) {
case 1:
{
system("cls");
main();
}
break;
case 2:
return 0;
break;

return 0;
}
system("pause");

return 0;
}

You might also like