Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // karol_d.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <iostream>
- #include <time.h>
- #include <iomanip>
- using namespace std;
- const int MAX_N = 100;
- const int MAX_M = 100;
- int _tmain(int argc, _TCHAR* argv[])
- {
- srand(time(0));
- int n,m,a,b;
- int A[MAX_N][MAX_M];
- int k;
- int licznik = 0;
- cout << "Array dimensions: " << endl;
- cin >> n;
- cin >> m;
- cout << "Generate random numbers: " << endl;
- cin >> a;
- cin >> b;
- cout << "K: " << endl;
- cin >> k;
- for (int i = 0; i < n; i++){
- for (int j = 0; j < m; j++){
- A[i][j] = a + rand() % (b-a+1);
- }
- }
- for(int x = 0; x < (n-2); x++)
- {
- for(int y = 0; y < (m-2); y++)
- {
- int suma = 0;
- for(int i = 0; i < 3; i++)
- {
- for(int j = 0; j < 3; j++)
- suma = suma + A[x+i][y+j];
- }
- if(suma < k) licznik++;
- }
- }
- for (int i = 0; i < n; i++){ //array
- for (int j = 0; j < m; j++){
- cout << setw(4) << A[i][j];
- }
- cout << endl;
- }
- cout << "Ile: " << licznik << endl;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement