Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <ctime>
- #include <cstdlib>
- using namespace std;
- int main()
- {
- setlocale(LC_ALL,"Rus");
- srand(time(0));
- vector<int> v;
- int N;
- int a=0, b=0;
- int** matrix;
- cout << "Квадратная матрица. Введите N = ";
- cin >> N;
- matrix = new int*[N];
- for (int i=0; i<N; i++)
- matrix[i]=new int[N];
- cout << "Изначальная матрица:\n";
- for (int i=0; i<N; i++){
- for(int j=0; j<N; j++) {
- matrix[i][j]=rand()%10-2;
- cout << matrix[i][j]<<" ";
- } cout <<endl;
- }
- for (int i=0; i<N; i++){
- for(int j=0; j<N; j++) {
- a=matrix[i][j];
- if (a>0 && b==i)
- {
- v.push_back(a); b++;
- }
- }
- }
- for (auto x: v){
- cout << x << " ";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement