Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Двумерный массив.doc
Скачиваний:
0
Добавлен:
01.03.2025
Размер:
288.26 Кб
Скачать

Void main(){

Int a [size][size];

int n;

cout << "ROW " << endl;

cin >> n;

if((n > 100 && n <= 0)){

cout<<"Error size"; system("pause"); return;

}

cout << "Massiv A" << endl;

Vvod(n, A);

cout << "\nMassiv A" << endl;

Vivod(n, A);

F(n, A);

cout << "\n\nMassiv A" << endl;

Vivod(n, A);

cout << endl;

}

  1. Дана матрица целых чисел A[M][N]. Изменить порядок следования элементов побочной диагонали на противоположный. Вывести на экран исходную и преобразованную матрицы.

#include <iostream>

#include <math.h>

#define SIZE 100

using namespace std;

void Vvod(int n, int arr[][SIZE])

{

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

{

for(int j = 0; j < n; ++j){

cout << "[" << i << "]["<< j <<"]: ";

cin >> arr[i][j];

}

}

}

void F(int n, int arr[][SIZE])

{

for(int i = 0; i < n/2; ++i)

{

int buf =arr[n-i-1][i] ;

arr[n-i-1][i] = arr[i][n-i-1 ];

arr[i][n-i-1] = buf;

}

}

void Vivod(int n,int arr[][SIZE])

{

for(int i = 0; i < n; ++i){

for(int j = 0; j < n; ++j){

cout << arr[i][j] << " ";

}

cout<<endl;

}

cout<<endl;

}

Void main(){

Int a [size][size];

int n;

cout << "ROW " << endl;

cin >> n;

if((n > 100 && n <= 0)){

cout<<"Error size"; system("pause"); return;

}

cout << "Massiv A" << endl;

Vvod(n, A);

cout << "\nMassiv A" << endl;

Vivod(n, A);

F(n, A);

cout << "\n\nMassiv A" << endl;

Vivod(n, A);

cout << endl;

system("pause");

}

  1. Дана матрица целых чисел A[M][N]. Вычислить сумму элементов на главной диагонали. Результат вывести на экран.

#include <iostream>

#include <math.h>

#define SIZE 100

using namespace std;

Void Vvod(int n, int m, int arr[][size])

{

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

{

for(int j = 0; j < m; ++j){

cout << "[" << i << "]["<< j <<"]: ";

cin >> arr[i][j];

}

}

}

int F(int n, int m, int arr[][SIZE])

{

int sum = 0;

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

for(int j = 0; j < m; ++j){

if(i == j) sum += arr[i][j];

}

return sum;

}

void Vivod(int n,int m,int arr[][SIZE])

{

for(int i = 0; i < n; ++i){

for(int j = 0; j < m; ++j){

cout << arr[i][j] << " ";

}

cout<<endl;

}

cout<<endl;

}

Void main(){

int A [SIZE][SIZE], sum;

int n,m;

cout << "ROW" << endl;

cin >> n;

cout << "COL" << endl;

cin >> m;

if((n > 100 && n <= 0) || (m > 100 && m <= 0 )){

cout<<"Error size"; system("pause"); return;

}

cout << "Massiv A" << endl;

Vvod(n,m, a);

cout << "\nMassiv A" << endl;

Vivod(n, m, a);

sum = F(n, m, A);

cout << "SUMMA=" <<sum<< endl;

cout << endl;

}

  1. Дана матрица вещественных чисел X[M][N]. Вычислить сумму значений каждого столбца матрицы и вывести итоговый массив на экран.

#include <iostream>

#include <math.h>

#define SIZE 100

using namespace std;

void Vvod(int n, int m, double arr[][SIZE], double *y)

{

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

{

for(int j = 0; j < m; ++j){

cout << "[" << i << "]["<< j <<"]: ";

cin >> arr[i][j];

y[j] += arr[i][j];

}

}

}