Advertisement
Guest User

Untitled

a guest
Oct 30th, 2014
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.09 KB | None | 0 0
  1. // karol_d.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6. #include <time.h>
  7. #include <iomanip>
  8.  
  9. using namespace std;
  10.  
  11. const int MAX_N = 100;
  12. const int MAX_M = 100;
  13.  
  14. int _tmain(int argc, _TCHAR* argv[])
  15. {
  16.     srand(time(0));
  17.     int n,m,a,b;
  18.     int A[MAX_N][MAX_M];
  19.     int k;
  20.     int licznik = 0;
  21.  
  22.  
  23.     cout << "Array dimensions: " << endl;
  24.     cin >> n;
  25.     cin >> m;
  26.  
  27.     cout << "Generate random numbers: " << endl;
  28.     cin >> a;
  29.     cin >> b;
  30.  
  31.     cout << "K: " << endl;
  32.     cin >> k;
  33.  
  34.  
  35.     for (int i = 0; i < n; i++){
  36.         for (int j = 0; j < m; j++){
  37.             A[i][j] = a + rand() % (b-a+1);
  38.         }
  39.     }
  40.  
  41.  
  42.     for(int x = 0; x < (n-2); x++)
  43.     {
  44.         for(int y = 0; y < (m-2); y++)
  45.         {
  46.             int suma = 0;
  47.  
  48.  
  49.             for(int i = 0; i < 3; i++)
  50.             {
  51.                 for(int j = 0; j < 3; j++)
  52.                     suma = suma + A[x+i][y+j];
  53.             }
  54.  
  55.             if(suma < k) licznik++;
  56.         }
  57.     }
  58.  
  59.  
  60.  
  61.     for (int i = 0; i < n; i++){    //array
  62.         for (int j = 0; j < m; j++){
  63.             cout << setw(4) << A[i][j];
  64.  
  65.         }
  66.         cout << endl;
  67.     }
  68.  
  69.     cout << "Ile: " << licznik << endl;
  70.  
  71.     system("pause");
  72.  
  73.     return 0;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement