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;
- for (i=0; i<5; i++)
- {
- for (j=0; j<5; j++)
- {
- if (a[i][j]>max)
- max=a[i][j];
- }
- }
- max;
- return (max);
- }
- void func2 (int a[5][5])
- {
- int i,j,k;
- for (i=0; i<5; i++)
- {
- for (j=0; j<4; j++)
- {
- if(a[0][j]>a[0][j + 1])
- {
- k = a[0][j];
- a[0][j] = a[0][j + 1];
- a[0][j + 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];
- 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<<"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<<"Матрица с замененными отрицательными элементами на max"<<endl;
- func3(a,func(a));
- 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