Tomki

Untitled

Mar 10th, 2016
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.97 KB | None | 0 0
  1. //программа 1
  2. #include <iostream>
  3. #include <stdio.h>
  4. using namespace std;
  5. int main()
  6. {
  7. setlocale(LC_ALL, "RUS");
  8. int i,j,a[10][20],n,m,k=0,*u1=NULL,*u2=NULL,t;
  9. do
  10. {
  11. printf("Введите количество столбцов и строк матрицы A\n");
  12. scanf("%d%d",&m,&n);
  13. }
  14. while((n<0 || m<0) || (n*m<5));
  15. printf("Введите матрицу, состоящую из %d столбцов и %d строк:\n",m,n);
  16. for(i=0;i<n;i++)
  17. for(j=0;j<m;j++)
  18. scanf("%d",&a[i][j]);
  19. printf("Матрица А:\n");
  20. for(i=0;i<n;i++)
  21. {
  22. for(j=0;j<m;j++)
  23. printf("%4d",*(*(a+i)+j));
  24. printf("\n");
  25. }
  26. for(i=0;i<n;i++)
  27. for(j=0;j<m;j++)
  28. if(a[i][j]<0)
  29. {
  30. k++;
  31. if(k==2 && u1==NULL)
  32. u1=&a[i][j];
  33. if(k==5 && u2==NULL)
  34. u2=&a[i][j];
  35. }
  36. if(u1==NULL || u2==NULL)
  37. printf("Перестановок в матрице нет");
  38. else
  39. {
  40. t=*u1;
  41. *u1=*u2;
  42. *u2=t;
  43. printf("измененная матрица А:\n");
  44. for(i=0;i<n;i++)
  45. {
  46. for(j=0;j<m;j++)
  47. printf("%4d",*(*(a+i)+j));
  48. printf("\n");
  49. }
  50. }
  51. }
  52. //программа 2
  53. #include <iostream>
  54. using namespace std;
  55. void input_matr(int a[][20],int *n, int *m)
  56. {
  57. int (*u)[20],*uj;
  58. do
  59. {
  60. cout << "Введите количество столбцов и строк матрицы А:" << endl;
  61. cin >> *m >> *n;
  62. }
  63. while(*n<0 || *m<0 || (*n)*(*m)<5);
  64. cout << endl;
  65. cout << "Введите элементы матрицы"<< endl;
  66. for(u=a;u<a+*n;u++)
  67. for(uj=*u;uj<*u+*m;uj++)
  68. cin >> *uj;
  69. cout << "Матрица A:"<< endl;
  70. for(u=a;u<a+*n;u++)
  71. {
  72. for(uj=*u;uj<*u+*m;uj++)
  73. cout << *uj << " " ;
  74. cout << endl;
  75. }
  76. }
  77. void output_matr(int a[][20],int n, int m, int *u1, int *u2 )
  78. {
  79. int (*u)[20],*uj,t;
  80. if(u1==NULL || u2==NULL )
  81. cout << "Перестановок нет" << endl;
  82. else
  83. {
  84. t=*u1;
  85. *u1=*u2;
  86. *u2=t;
  87. cout << "Матрица A c перестановками:"<< endl;
  88. for(u=a;u<a+n;u++)
  89. {
  90. for(uj=*u;uj<*u+m;uj++)
  91. cout << *uj << " " ;
  92. cout << endl;
  93. }
  94. }
  95. }
  96. void change(int a[][20],int **u1,int **u2,int n,int m)
  97. {
  98. int (*u)[20],*uj,k;
  99. for(u=a;u<a+n;u++)
  100. for(uj=*u;uj<*u+m;uj++)
  101. {
  102. if(*uj<0)
  103. k++;
  104. if(*u1==NULL && k==2)
  105. *u1=uj;
  106. if(*u2==NULL && k==5)
  107. *u2=uj;
  108. }
  109. }
  110. int main()
  111. {
  112. setlocale(LC_ALL,"RUS");
  113. int a[10][20],m,n,*u1=NULL, *u2=NULL;
  114. input_matr(a, &n, &m);
  115. change(a,&u1,&u2,n,m);
  116. output_matr(a,n,m,u1,u2);
  117. }
Advertisement
Add Comment
Please, Sign In to add comment