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