Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdlib.h>
- #include<time.h>
- #include "stdafx.h"
- #include <iostream>
- #define M 8
- #define N 10
- using namespace std;
- void generujMaticuNahodne(int matica[M][N], int m, int n);
- void vypisMaticu(int matica[M][N], int m, int n);
- void minusujRiadok(int matica[M][N], int m, int n, unsigned short R);
- void vynasob2Obvod(int matica[M][N], int m, int n);
- void odpocitajStlpecOdStlpca(int matica[M][N], int m, int n, unsigned short S1, unsigned short S2);
- unsigned short pocetRovnakychPrvkovVStlpcoch(int matica[M][N], int m, int n, unsigned short S1, unsigned short S2);
- bool obsahujeRiadokNeparneCislo(int matica[M][N], int m, int n, unsigned short R);
- int main()
- {
- int m = 8;
- int n = 10;
- unsigned short R1, R2, S1, S2, S3, S4;
- int MATICA[M][N];
- generujMaticuNahodne(MATICA, m, n);
- vypisMaticu(MATICA, m, n);
- cout << "Zadaj index riadku " << endl;
- cin >> R1;
- minusujRiadok(MATICA, m, n, R1);
- vypisMaticu(MATICA, m, n);
- cout << endl;
- vynasob2Obvod(MATICA, m, n);
- vypisMaticu(MATICA, m, n);
- cout << "Zadaj prvy stlpec ";
- cin >> S1;
- cout << "Zadaj druhy stlpec ";
- cin >> S2;
- odpocitajStlpecOdStlpca(MATICA, m, n, S1, S2);
- vypisMaticu(MATICA, m, n);
- cout << "Zadaj prvy stlpec ";
- cin >> S3;
- cout << "Zadaj druhy stlpec ";
- cin >> S4;
- cout << "Pocet rovnakych prvkov v zadanych stlpcoch je : " << pocetRovnakychPrvkovVStlpcoch(MATICA, m, n, S3, S4) << endl;
- cout << "Zadaj index riadku : ";
- cin >> R2;
- if (obsahujeRiadokNeparneCislo(MATICA, m, n, R2))
- {
- cout << "Riadok obsahuje neparne cislo" << endl;
- }
- else
- cout << "neobsahuje neparne cislo" << endl;
- system("pause");
- return 0;
- }
- void generujMaticuNahodne(int matica[M][N], int m, int n)
- {
- for (int i = 0; i < m; i++)
- {
- for (int j = 0; j < n; j++)
- {
- matica[i][j] = -30 + (rand() % (-10 - (-30) + 1));
- }
- }
- }
- void vypisMaticu(int matica[M][N], int m, int n)
- {
- for (int i = 0; i < m; i++)
- {
- for (int j = 0; j < n; j++)
- {
- cout << matica[i][j] << "\t";
- }
- cout << endl;
- }
- }
- void minusujRiadok(int matica[M][N], int m, int n, unsigned short R)
- {
- for (int i = 0; i < m; i++)
- {
- for (int j = 0; j < n; j++)
- {
- if (i == R-1)
- {
- matica[i][j] *= -1;
- }
- }
- }
- }
- void vynasob2Obvod(int matica[M][N], int m, int n)
- {
- for (int i = 0; i < m; i++)
- {
- for (int j = 0; j < n; j++)
- {
- if (i == 0 || i == m - 1 || j == 0 || j == n - 1)
- matica[i][j] = matica[i][j] * 2;
- }
- }
- }
- void odpocitajStlpecOdStlpca(int matica[M][N], int m, int n, unsigned short S1, unsigned short S2)
- {
- for (int i = 0; i < m; i++)
- {
- for (int j = 0; j < n; j++)
- {
- if (j == S1)
- {
- matica[i][S2] -= matica[i][S1];
- }
- }
- }
- }
- unsigned short pocetRovnakychPrvkovVStlpcoch(int matica[M][N], int m, int n, unsigned short S1, unsigned short S2)
- {
- unsigned short pocetRovnakych = 0;
- for (int i = 0; i < m; i++)
- {
- if (matica[i][S1] == matica[i][S2])
- pocetRovnakych++;
- }
- return pocetRovnakych;
- }
- bool obsahujeRiadokNeparneCislo(int matica[M][N], int m, int n, unsigned short R)
- {
- unsigned short neparne = 0;
- for (int i = 0; i < m; i++)
- {
- for (int j = 0; j < n; j++)
- {
- if (i == R)
- {
- if (matica[R][j] % 2 == 1)
- neparne++;
- }
- }
- }
- if (neparne > 0) return true;
- else return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement