Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <clocale>
- #include <ctime>
- #include <cmath>
- using namespace std;
- #define M 5
- #define N 5
- bool differentThanZero(int array[][N], size_t rows);
- void fillTheArray(int array[][N], size_t rows);
- void printTheArray(int array[][N], size_t rows);
- int main(){
- setlocale(LC_ALL, "Bulgarian");
- srand(time(NULL));
- int array[M][N];
- fillTheArray(array, M);
- printTheArray(array, M);
- cout << endl;
- cout << boolalpha << differentThanZero(array, M);
- return 0;
- }
- //да се провери дали всички елементи под главния диагонал (без него) НЕ са 0. (при откриване на 1 нула прекъсва)
- bool differentThanZero(int array[][N], size_t rows){
- for (size_t j = 0; j < N; j++){
- for (size_t i = j+1; i < M; i++)
- {
- if (array[i][j] == 0) return false;
- }
- }
- return true;
- }
- void fillTheArray(int array[][N], size_t rows){
- for (size_t i = 0; i < M; i++)
- {
- for (size_t j = 0; j < N; j++){
- array[i][j] = rand() % 10 - 1;
- }
- }
- }
- //принтирам масив
- void printTheArray(int array[][N], size_t rows){
- cout << "Оригиналната матрица е това : " << endl;
- for (size_t i = 0; i < M; i++)
- {
- for (size_t j = 0; j < N; j++){
- cout << array[i][j] << "\t";
- }
- cout << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement