Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <math.h>
- #include <cstring>
- using namespace std;
- double func(int a[5][5])
- {
- int i, j;
- double p=0;
- for (i=0; i<5; i++)
- {
- for (j=0; j<5; j++)
- {
- if (a[i][j]%2==0)
- p=p+a[i][j];
- }
- }
- return (p);
- }
- void func2 (int a[5][5], int b[5], int n3)
- {
- int i, j,k=0,r=0;
- for (i=0; i<5; i++)
- {
- for (j=0; j<4; j++)
- {
- if(a[n3-1][j] > a[n3-1][j + 1])
- {
- k = a[n3-1][j];
- a[n3-1][j] = a[n3-1][j + 1];
- a[n3-1][j + 1] = k;
- }
- }
- }
- }
- void func3 (int a[5][5], int b[5])
- {
- int i=0, j=0, max;
- for (j=0; j<5; j++)
- {
- max=-300000;
- for (i=0; i<5; i++)
- {
- if (a[i][j]>max)
- max=a[i][j];
- b[j]=max;
- }
- }
- }
- int _tmain(int argc, _TCHAR* argv[])
- {
- int i, j, n3;
- int a[5][5], b[5], s=0;
- setlocale (0,"rus");
- for (i=0; i<5;i++)
- {
- for (j=0; j<5;j++)
- {
- a[i][j]=-10+rand()%20;
- }
- }
- cout<<"Матрица 1"<<endl;
- for (i=0; i<5;i++)
- {
- for (j=0; j<5; j++)
- {
- cout<<a[i][j]<<"\t";
- }
- cout<<endl;
- }
- cout<<endl;
- cout<<"Сумма= "<<func(a)<<endl;
- cout<<"Введите номер строки для сортировки"<<endl;
- cin>>n3;
- func2(a,b,n3);
- cout<<"Отсортированная строчка"<<endl;
- for (i=0; i<5;i++)
- {
- for (j=0; j<5; j++)
- {
- cout<<a[i][j]<<"\t";
- }
- cout<<endl;
- }
- func3(a,b);
- cout<<"Максимумы в каждом столбце"<<endl;
- for(i=0;i<5;i++)
- {
- cout<<b[i]<<"\t";
- }
- cout<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement