Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- using namespace std;
- void enterMatrix(double matrix[6][6]);
- void maxAndMinElements(double matrix[6][6]);
- void negativeAverage(double matrix[6][6]);
- void notZeroMultiplication(double matrix[6][6]);
- void printMatrix(double matrix[6][6]);
- void main()
- {
- double matrix[6][6]; // съхранява въведените 5 х 5 и макс елементи от редове, минимални от стълбове
- int size = 0;
- while (true)
- {
- cout << "Izberi 1 za vavezdane na masiv KV(5, 5)" << endl;
- cout << "Izberi 2 za namirane na max elementi po red i min po koloni" <<
- "i sahranqvaneto im saotvento kato 6-ta kolonai 6-ti red" << endl;
- cout << "Izberi 3 za namirane na sredno aritmetichno ot otricatelni chisla" << endl;
- cout << "Izberi 4 za namirane na proizvedenie ot chosla razlichni ot 0" << endl;
- cout << "Izberi 5 za izvezdane na matricata KV(6, 6)" << endl;
- int izbor;
- cout << "Izbor: ";
- do
- {
- cin >> izbor;
- } while (izbor < 1 && izbor > 6);
- switch (izbor)
- {
- case 1:
- enterMatrix(matrix);
- break;
- case 2:
- maxAndMinElements(matrix);
- break;
- case 3:
- negativeAverage(matrix);
- break;
- case 4:
- notZeroMultiplication(matrix);
- break;
- case 5:
- printMatrix(matrix);
- break;
- }
- }
- }
- void enterMatrix(double matrix[6][6])
- {
- cout << "Vavedete vashata 5 x 5 matrica: " << endl;
- for (int i = 0; i < 5; i++) //обхождане по редове
- {
- for (int j = 0; j < 5; j++) //обхождане на колони от ред
- {
- cin >> matrix[i][j];
- }
- }
- }
- void maxAndMinElements(double matrix[6][6])
- {
- //намиране на максимални елементи по редове
- for (int i = 0; i < 5; i++) //обхождане по редове
- {
- double maxRow = matrix[i][0]; //най-голямо число в реда
- for (int j = 0; j < 5; j++) //обхождане на колони от ред
- {
- if (maxRow < matrix[i][j])
- {
- maxRow = matrix[i][j];
- }
- }
- matrix[i][5] = maxRow; // число за 6-та колона от реда
- }
- //намиране на минимални елементи по стълбове
- for (int i = 0; i < 6; i++) //обхождане по колони
- {
- double minCol = matrix[i][0]; //минимално число в колоната
- for (int j = 0; j < 5; j++) //обхождане по редове
- {
- if (matrix[j][i] < minCol)
- {
- minCol = matrix[j][i];
- }
- }
- matrix[5][i] = minCol; //число за 6-ти ред от колоната
- }
- }
- void negativeAverage(double matrix[6][6])
- {
- double suma = 0; //сума на отрицателни числа
- int broj = 0; //брой отрицателни числа
- for (int i = 0; i < 6; i++) //обхождане по редове
- {
- for (int j = 0; j < 6; j++) //обхождане на колони от ред
- {
- if (matrix[i][j] < 0)
- {
- suma += matrix[i][j];
- broj++;
- }
- }
- }
- if (broj == 0)
- {
- cout << "Nqma otricatelni chisla v masiva!" << endl;
- }
- else
- {
- cout << "Sredno aritmetichnoto na otricatelnite e: " << suma / broj << endl;
- }
- }
- void notZeroMultiplication(double matrix[6][6])
- {
- double multiply = 1;
- for (int i = 0; i < 6; i++) //обхождане по редове
- {
- for (int j = 0; j < 6; j++) //обхождане на колони от ред
- {
- if (matrix[i][j] != 0)
- {
- multiply *= matrix[i][j];
- }
- }
- }
- cout << "Proizvedenieto na nenulevite chisla e: " << multiply << endl;
- }
- void printMatrix(double matrix[6][6])
- {
- for (int i = 0; i < 6; i++) //обхождане по редове
- {
- cout << "Red " << i + 1 << ": "; // +1, за да изписва ред 1, а не ред 0
- for (int j = 0; j < 6; j++) //обхождане на колони от ред
- {
- cout << matrix[i][j] << " ";
- }
- cout << endl; // за да може да принтира всеки ред от матрицата на нови редове
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement