ChameL1oN

Уч_Практика_ЯП_4_задача

Jan 23rd, 2015
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. #include <iostream>
  2. #include <locale>
  3.  
  4.  
  5. using namespace std;
  6.  
  7.  
  8. void Pechat(int** mass, int n){
  9. for (int i = 0; i < n; i++)
  10. {
  11. for (int j = 0; j < n; j++)
  12. {
  13. cout << mass[i][j] << " ";
  14. }
  15. cout << endl;
  16. }
  17. }
  18.  
  19. int* mass(int m,int d){
  20. int* mass = new int[m];
  21. for (int i = 0; i < m; i++){
  22. cout << "Введите элемент [" << d << "," << i << "] " << endl;
  23. cin >> mass[i];
  24. }
  25. return mass;
  26. }
  27.  
  28. int** matr(int m){
  29. int i = 0;
  30. int** matr = new int*[m];
  31. while (i < m){
  32. matr[i] = mass(m,i);
  33. i++;
  34. }
  35. return matr;
  36. }
  37.  
  38. void main(){
  39. int max, j, i, p,m;
  40. setlocale(LC_ALL, "rus");
  41. cout << "Введите размерность матрицы" << "\n";
  42. cin >> m;
  43. int** a = matr(m);
  44. Pechat(a, m);
  45. cout << endl;
  46. for (i = 0; i < m; i++){
  47. max = a[i][i];
  48. for (j = 0; j < m; j++)
  49. {
  50. if (max < a[i][j]) { max = a[i][j]; p = j; }
  51. }
  52. a[i][p] = a[i][i];
  53. a[i][i] = max;
  54. }
  55. cout << endl;
  56. cout << "Матрица после обработки :" << endl;
  57. cout << endl;
  58. Pechat(a, m);
  59. }
Advertisement
Add Comment
Please, Sign In to add comment