Advertisement
Uncleeee

Untitled

Apr 24th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <ctime>
  4. #include <cstdlib>
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. setlocale(LC_ALL,"Rus");
  10. srand(time(0));
  11. vector<int> v;
  12. int N;
  13. int a=0, b=0;
  14. int** matrix;
  15. cout << "Квадратная матрица. Введите N = ";
  16. cin >> N;
  17. matrix = new int*[N];
  18. for (int i=0; i<N; i++)
  19. matrix[i]=new int[N];
  20.  
  21. cout << "Изначальная матрица:\n";
  22. for (int i=0; i<N; i++){
  23. for(int j=0; j<N; j++) {
  24. matrix[i][j]=rand()%10-2;
  25. cout << matrix[i][j]<<" ";
  26. } cout <<endl;
  27. }
  28.  
  29. for (int i=0; i<N; i++){
  30. for(int j=0; j<N; j++) {
  31. a=matrix[i][j];
  32. if (a>0 && b==i)
  33. {
  34. v.push_back(a); b++;
  35. }
  36. }
  37. }
  38.  
  39. for (auto x: v){
  40. cout << x << " ";
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement