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 b[25], int p)
- {
- int i;
- double max=-3000000;
- for (i=0; i<p; i++)
- {
- if (b[i]>max)
- max=b[i];
- }
- return (max);
- }
- void func2 (int a[5][5], int b[25],int *r)
- {
- int i, j, k=3, p=0;
- for (i=0; i<5; i++)
- {
- for (j=4; j>k; j--)
- {
- if(a[i][j]<0)
- {
- b[p]=a[i][j];
- p=p+1;
- }
- }
- k--;
- }
- *r=p;
- }
- double func3(int b[25], int p)
- {
- int i, s=0,r;
- for (i=0; i<p; i++)
- {
- s=s+b[i];
- }
- r=s/p;
- return (r);
- }
- int _tmain(int argc, _TCHAR* argv[])
- {
- int i, j,p;
- int a[5][5], b[25];
- 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;
- func2(a,b, &p);
- for (i=0;i<p;i++)
- {
- cout<<b[i]<<endl;
- }
- cout<<endl;
- cout<<"Max = "<<func(b,p)<<endl;
- cout<<"Среднее арифмитическое = "<<func3(b,p)<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement