Bob103

с массивом

Dec 22nd, 2015
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. int **creat(int &n, int &m)
  4. {
  5. cout << "n="; cin >> n; cout << "m="; cin >> m;
  6. int **mas = new int*[n];
  7. for (int i = 0; i < n; ++i)
  8. mas[i] = new int[m];
  9. for (int i = 0; i < n; ++i)
  10. for (int j = 0; j < m; ++j)
  11. {
  12. cout << "mas[" << i << "][" << j << "]="; cin >> mas[i][j];
  13. }
  14. return mas;
  15. }
  16. int main()
  17. {
  18. int n, m,maxj;
  19. cout << "n="; cin >> n; cout << "m="; cin >> m;
  20. int **a = creat(n, m);int max;
  21. for (int i = 0; i < n; ++i)
  22. {max=a[i][0];
  23. maxj =0;
  24. for (int j = 0; j < m; ++j)
  25. if (a[i][j]>max)
  26. {
  27. max = a[i][j];
  28. maxj=j;
  29. }
  30. a[i][maxj]*=-1;
  31. }
  32. cout<<"Полученная матрица:";
  33. for(int i=0;i<n;i++)
  34. {
  35. for(int j=0;j<n;j++)
  36. cout<<a[i][j]<<" ";
  37. cout<<endl;
  38. }
  39. for (int i = 0; i < n; ++i)
  40. delete[]a[i];
  41. delete[]a;
  42. system("pause");
  43. return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment