Advertisement
Guest User

Untitled

a guest
Dec 4th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <iomanip>
  4. #include <ctime>
  5. using namespace std;
  6. const int x=3;
  7. void input(int a[x][x]){
  8. srand(time(NULL));
  9. for(int i=0; i<x; i++)
  10. {for(int j=0; j<x; j++)
  11. { a[i][j]=rand()%19-9;
  12. cout<<a[i][j]<<" "; }
  13. cout<<endl;}}
  14.  
  15. void minmax(int a[x][x]){
  16. int r,s;
  17. cout<<"Виберіть стовбець матриці:";
  18. cin>>s;
  19. cout<<"Виберіть рядок матриці:";
  20. cin>>r;
  21. s--;
  22. r--;
  23. int max=a[0][s],min=a[r][0];
  24. for (int i=0;i<x;i++){if(a[i][s]>max) max=a[i][s];}
  25. for (int j=0;j<x;j++){if(a[r][j]<min) min=a[r][j];}
  26. for (int i=0;i<x;i++){if(a[i][s]==max) a[i][s]=min;}
  27. for (int j=0;j<x;j++){if(a[r][j]==min) a[r][j]=max;}
  28. cout<<endl;
  29. cout<<"Максимальний елемент стовбця="<<max<<endl;
  30. cout<<"Мінімальний елемент рядка="<<min<<endl;}
  31.  
  32. void output2(int a[x][x]){
  33. for (int i=0;i<x;i++){
  34. for(int j=0;j<x;j++){
  35. cout<<setw(2)<<a[i][j]<<" ";
  36. }
  37. cout<<endl;}}
  38.  
  39. int main()
  40. {int a[x][x];
  41. setlocale(LC_ALL, "rus");
  42. cout<<" "<<endl;
  43. for(int i=0; i<3;i++){
  44. input(a);
  45. minmax(a);
  46. output2(a);}
  47. setlocale(LC_ALL,"OCP");
  48. system("pause");
  49. return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement