Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //программа 1
- #include <iostream>
- #include <stdio.h>
- using namespace std;
- int main()
- {
- setlocale(LC_ALL, "RUS");
- int i,j,a[10][20],n,m,k=0,*u1=NULL,*u2=NULL,t;
- do
- {
- printf("Введите количество столбцов и строк матрицы A\n");
- scanf("%d%d",&m,&n);
- }
- while((n<0 || m<0) || (n*m<5));
- printf("Введите матрицу, состоящую из %d столбцов и %d строк:\n",m,n);
- for(i=0;i<n;i++)
- for(j=0;j<m;j++)
- scanf("%d",&a[i][j]);
- printf("Матрица А:\n");
- for(i=0;i<n;i++)
- {
- for(j=0;j<m;j++)
- printf("%4d",*(*(a+i)+j));
- printf("\n");
- }
- for(i=0;i<n;i++)
- for(j=0;j<m;j++)
- if(a[i][j]<0)
- {
- k++;
- if(k==2 && u1==NULL)
- u1=&a[i][j];
- if(k==5 && u2==NULL)
- u2=&a[i][j];
- }
- if(u1==NULL || u2==NULL)
- printf("Перестановок в матрице нет");
- else
- {
- t=*u1;
- *u1=*u2;
- *u2=t;
- printf("измененная матрица А:\n");
- for(i=0;i<n;i++)
- {
- for(j=0;j<m;j++)
- printf("%4d",*(*(a+i)+j));
- printf("\n");
- }
- }
- }
- //программа 2
- #include <iostream>
- using namespace std;
- void input_matr(int a[][20],int *n, int *m)
- {
- int (*u)[20],*uj;
- do
- {
- cout << "Введите количество столбцов и строк матрицы А:" << endl;
- cin >> *m >> *n;
- }
- while(*n<0 || *m<0 || (*n)*(*m)<5);
- cout << endl;
- cout << "Введите элементы матрицы"<< endl;
- for(u=a;u<a+*n;u++)
- for(uj=*u;uj<*u+*m;uj++)
- cin >> *uj;
- cout << "Матрица A:"<< endl;
- for(u=a;u<a+*n;u++)
- {
- for(uj=*u;uj<*u+*m;uj++)
- cout << *uj << " " ;
- cout << endl;
- }
- }
- void output_matr(int a[][20],int n, int m, int *u1, int *u2 )
- {
- int (*u)[20],*uj,t;
- if(u1==NULL || u2==NULL )
- cout << "Перестановок нет" << endl;
- else
- {
- t=*u1;
- *u1=*u2;
- *u2=t;
- cout << "Матрица A c перестановками:"<< endl;
- for(u=a;u<a+n;u++)
- {
- for(uj=*u;uj<*u+m;uj++)
- cout << *uj << " " ;
- cout << endl;
- }
- }
- }
- void change(int a[][20],int **u1,int **u2,int n,int m)
- {
- int (*u)[20],*uj,k;
- for(u=a;u<a+n;u++)
- for(uj=*u;uj<*u+m;uj++)
- {
- if(*uj<0)
- k++;
- if(*u1==NULL && k==2)
- *u1=uj;
- if(*u2==NULL && k==5)
- *u2=uj;
- }
- }
- int main()
- {
- setlocale(LC_ALL,"RUS");
- int a[10][20],m,n,*u1=NULL, *u2=NULL;
- input_matr(a, &n, &m);
- change(a,&u1,&u2,n,m);
- output_matr(a,n,m,u1,u2);
- }
Advertisement
Add Comment
Please, Sign In to add comment