Advertisement
LabiinfaCibGyti

biblia4

Dec 17th, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.49 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <math.h>
  4. #include "biblia4.h"
  5. using namespace std;
  6. int _tmain(int argc, _TCHAR* argv[])
  7. {
  8.     int i=0, j=0,k1,k2;
  9.     int a[5][5];
  10.     setlocale (0,"rus");
  11.     for (i=0; i<5;i++)
  12.     {
  13.         for (j=0; j<5;j++)
  14.         {
  15.             a[i][j]=-10+rand()%20;
  16.         }
  17.     }
  18.     cout<<"Матрица 1"<<endl;
  19.     func3(a);
  20.     cout<<endl;
  21.     func(a,&k1,&k2);
  22.     cout<<"Сумма положительных элементов= "<<k1<<"\tКол-во отрицательных элементов= "<<k2<<endl;
  23.     cout<<endl;
  24.     cout<<"Кол-во положительных элементов в четных строках матрицы= "<<func2(a)<<endl;
  25.     cout<<endl;
  26.     return 0;
  27. }
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38. #include "stdafx.h"
  39. #include <iostream>
  40. #include <math.h>
  41. #include "biblia4.h"
  42. using namespace std;
  43. void func(int a[5][5], int *s, int *n)
  44. {
  45.     int i=0, j=0; *s=0; *n=0;
  46.     for (i=0; i<5; i++)
  47.     {
  48.         for (j=0; j<5; j++)
  49.         {
  50.             if (a[i][j]>0)
  51.                 *s=*s+a[i][j];
  52.             if (a[i][j]<0)
  53.                 *n=*n+1;
  54.         }
  55.     }
  56. }
  57. double func2(int a[5][5])
  58. {
  59.     int i, j, p=0;
  60.     for (i=0; i<5; i++)
  61.     {
  62.         for (j=0; j<5; j++)
  63.         {
  64.             if (((i+1)%2==0) && (a[i][j]>0))
  65.                 p=p+1;
  66.         }
  67.     }
  68.     return (p);
  69. }
  70. void func3 (int a[5][5])
  71. {
  72.     int i,j;
  73.     for (i=0; i<5;i++)
  74.     {
  75.         for (j=0; j<5; j++)
  76.         {
  77.             cout<<a[i][j]<<"\t";
  78.         }
  79.         cout<<endl;
  80.     }
  81. }
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89. void func(int a[5][5], int *s, int *n);
  90. double func2(int a[5][5]);
  91. void func3 (int a[5][5]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement