Advertisement
Guest User

Zadanie 1

a guest
Jan 15th, 2020
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.49 KB | None | 0 0
  1. #include <iostream>
  2. #include <time.h>
  3.  
  4. int main() {
  5.  
  6.     srand(time(0));
  7.  
  8.     const int M = 4;
  9.     const int N = 3;
  10.  
  11.     const float R = rand() % 1000 / 100.0;
  12.     std::cout << "R = " << R << "\n";
  13.  
  14.     float macierz[N][M];
  15.  
  16.     for (int i = 0; i < N; i++) {
  17.  
  18.         if (i == 0) {
  19.             for (int j = 0; j < M; j++) {
  20.                 macierz[i][j] = rand() % 1000 / 100.0;
  21.             }
  22.         }
  23.         else {
  24.             int suma_poprzedniego_wiersza = 0;
  25.             int poprzedni_wiersz = i - 1;
  26.             for (int z = 0; z < M; z++) {
  27.                 suma_poprzedniego_wiersza += macierz[poprzedni_wiersz][z];
  28.                //std::cout << macierz[poprzedni_wiersz][z] << "\t";
  29.             }
  30.             //std::cout << std::endl;
  31.             //std::cout << std::endl;
  32.             //std::cout << "suma wiersza: \t" << suma_poprzedniego_wiersza << std::endl;
  33.             //std::cout << "sr arytmetyczna: " << suma_poprzedniego_wiersza / M << std::endl;
  34.             //std::cout << "wynik: \t" << (suma_poprzedniego_wiersza / M) + R << std::endl;
  35.             //std::cout << std::endl;
  36.  
  37.             for (int j = 0; j < M; j++) {
  38.                 macierz[i][j] = (suma_poprzedniego_wiersza / M) + R;
  39.             }
  40.         }
  41.  
  42.     }
  43.     std::cout << std::endl;
  44.  
  45.     for (int i = 0; i < N; i++)
  46.     {
  47.         for (int j = 0; j < M; j++)
  48.             std::cout << macierz[i][j] << "\t";
  49.         std::cout << std::endl;
  50.     }
  51.  
  52.     std::cout << std::endl;
  53.  
  54.  
  55.  
  56.     return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement