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

Void Vivod(int n, int m, double 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(){

double A [SIZE][SIZE], B[SIZE]={0};

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,B);

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

Vivod(n, m, a);

cout << endl;

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

for(int j = 0; j < m; ++j) cout<<B[j]<<' ';

}

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

#include <iostream>

#include <math.h>

#define SIZE 100

using namespace std;

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

{

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

{

y[i]=1;

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

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

cin >> arr[i][j];

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

}

}

}

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], B[SIZE]={0};

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,B);

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

Vivod(n, m, a);

cout << endl;

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

for(int j = 0; j < n; ++j) cout<<B[j]<<' ';

}

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

#include <iostream>

#include <math.h>

#define SIZE 100

using namespace std;

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

{

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

{

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

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

cin >> arr[i][j];

}

}

}

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

{

double sum = 0;

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

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

}

return sum;

}

void Vivod(int n,double 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(){

double 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);

cout<<F(n, A)<<"\n\n";

system("pause");

}

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

#include <iostream>

#include <math.h>

#define SIZE 100

using namespace std;

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

{

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

{

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

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

cin >> arr[i][j];

}

}

}

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

{

double sum = 1;

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

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

}

return sum;

}

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

{

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

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

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

}

cout<<endl;

}

cout<<endl;

}