Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <random>
- #include <array>
- using IntMatrix = std::vector<std::vector<int>>;
- int randomInt(int min, int max) {
- static std::default_random_engine e{};
- std::uniform_int_distribution<int> d(min, max);
- return d(e);
- }
- IntMatrix createMatrix(std::array<unsigned int,2> shape) {
- std::vector<std::vector<int>> macierz (shape[0], std::vector<int>(shape[1]));
- for (int i=0; i<shape[0]; i++){
- for(int j=0; j<shape[1];j++){ macierz[i][j] = 0;}
- }
- return macierz;
- }
- IntMatrix randomMatrix(std::array<unsigned int,2> shape,int min,int max) {
- std::vector<std::vector<int>> macierz(shape[0], std::vector<int>(shape[1]));
- for (int i=0; i<shape[0];i++){
- for(int j=0; j<shape[0];j++){
- macierz[i][j] = randomInt(min,max);
- }
- }
- return macierz;
- }
- void print(std::vector<std::vector<int>> macierz){
- for(int i=0;i<macierz.size();i++){
- for(int j=0; j < macierz[0].size(); j++){
- std::cout<< macierz[i][j];
- if (j < macierz[0].size() - 1) std::cout << " ";
- }
- if (i<macierz[0].size() -1) std::cout << std::endl;
- }
- }
- int main(){
- std::array<unsigned int,2> macierz;
- unsigned int n,m;
- int min, max;
- std::cout<<"podaj wymiary macierzy"<<std::endl;
- macierz[0]=n;
- macierz[1]=m;
- std::cout << "ilosc wierszy:" <<std::endl;
- std::cin >> n;
- std::cout << "ilosc kolumn:" <<std::endl;
- std::cin >> m;
- print(createMatrix(macierz));
- std::cout << "podaj wymiary macierzy losowej";
- std::cout << "ilosc wierszy:" <<std::endl;
- std::cin >> n;
- std::cout << "ilosc kolumn:" <<std::endl;
- std::cin >> m;
- std::cout<< "podaj zakres liczb losowych" << std::endl;
- std::cout<< "od" << std::endl;
- std::cin>> min;
- std::cout<< "do" << std::endl;
- std::cin>> max;
- print(randomMatrix(macierz,min,max));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement