Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <math.h>
- #include "iomanip"
- using namespace std;
- int main()
- {
- setlocale (LC_ALL, "RUS");
- int i,j,N,M,a[20][20],max=0,min=0,k1,k2,pl=0,mn=0,nl=0;
- cout<<"Введите количество строк: "; cin>>N;
- cout<<"Введите количество столбцов: "; cin>>M;
- cout<<"Введите матрицу A: \n";
- for (i=0; i<N; i++)
- {
- for (j=0; j<M; j++)
- cin>>a[i][j];
- }
- for (j=0; j<M; j++)
- {
- for (i=0; i<N; i++)
- {
- if (a[i][j]>a[max][j])
- max=i;
- if (a[i][j]<a[min][j])
- min=i;
- if (a[i][j]>0)
- pl=pl+1;
- else if (a[i][j]<0)
- mn=mn+1;
- else nl=nl+1;
- }
- k1=a[max][j]; k2=a[min][j];
- a[max][j]=a[0][j]; a[0][j]=k1;
- a[min][j]=a[i-1][j]; a[i-1][j]=k2;
- max=min=0;
- }
- cout<<endl<<"Матрица A: \n";
- for (i=0; i<N; i++)
- {
- for (j=0; j<M; j++)
- cout<<a[i][j]<<"\t";
- cout<<endl;
- }
- cout<<endl;
- cout<<"Положительных элементов: "<<pl<<endl;
- cout<<"Отрицательных элементов: "<<mn<<endl;
- cout<<"Нулевых элементов: "<<nl<<endl;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment