Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <time.h>
- int main() {
- srand(time(0));
- const int M = 4;
- const int N = 3;
- const float R = rand() % 1000 / 100.0;
- std::cout << "R = " << R << "\n";
- float macierz[N][M];
- for (int i = 0; i < N; i++) {
- if (i == 0) {
- for (int j = 0; j < M; j++) {
- macierz[i][j] = rand() % 1000 / 100.0;
- }
- }
- else {
- int suma_poprzedniego_wiersza = 0;
- int poprzedni_wiersz = i - 1;
- for (int z = 0; z < M; z++) {
- suma_poprzedniego_wiersza += macierz[poprzedni_wiersz][z];
- //std::cout << macierz[poprzedni_wiersz][z] << "\t";
- }
- //std::cout << std::endl;
- //std::cout << std::endl;
- //std::cout << "suma wiersza: \t" << suma_poprzedniego_wiersza << std::endl;
- //std::cout << "sr arytmetyczna: " << suma_poprzedniego_wiersza / M << std::endl;
- //std::cout << "wynik: \t" << (suma_poprzedniego_wiersza / M) + R << std::endl;
- //std::cout << std::endl;
- for (int j = 0; j < M; j++) {
- macierz[i][j] = (suma_poprzedniego_wiersza / M) + R;
- }
- }
- }
- std::cout << std::endl;
- for (int i = 0; i < N; i++)
- {
- for (int j = 0; j < M; j++)
- std::cout << macierz[i][j] << "\t";
- std::cout << std::endl;
- }
- std::cout << std::endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement