Advertisement
labyyysosaaat

Untitled

Sep 28th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. setlocale(LC_ALL, "Russian");
  6. int rows=20;
  7. int cols=20;
  8. cout << "Введите количество строк: ";
  9. cin >> rows;
  10. cout << "Введите количество столбцов: ";
  11. cin >> cols;
  12. if (int(rows) != int(cols)) {
  13. cout << "Не квадратная матрица" << endl;
  14. system("pause");
  15. return 0;
  16. }
  17. int **arr = new int*[rows];
  18. for (int i = 0; i < rows; i++) {
  19. arr[i] = new int[cols];
  20. }
  21. for (int i = 0; i < rows; i++) {
  22.  
  23. for (int j = 0; j < cols; j++) {
  24. cout << "строка # "<< i+1 << "\t";
  25. cout << "столбец # "<<j+1 << "= ";
  26. cin >> arr[i][j];
  27.  
  28. }
  29. }
  30. for (int i = 0; i < rows; i++) {
  31. for (int j = 0; j < cols; j++) {
  32. cout << arr[i][j] << "\t";
  33.  
  34. }
  35. cout << endl;
  36. }
  37. for (int i = 0; i < rows; i++)
  38. {
  39. delete[] arr[i];
  40. }
  41. delete[] arr;
  42. system("pause");
  43. return 0;
  44.  
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement