Advertisement
Guest User

Untitled

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