Advertisement
LabiinfaCibGyti

laba7+10+11.5

Dec 4th, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.84 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <math.h>
  4. using namespace std;
  5.  
  6. int _tmain(int argc, _TCHAR* argv[])
  7. {
  8.     int i, j,k=0;
  9.     double min=2;
  10.         double a[5][5]={ {-3.8, 0, 5.3, 4.5, 0.5,},
  11.                             {0.2, -1.3, 0, -8.5, 3.5,},
  12.                             {-1.1, 1.8, 5.1, -8.2, 0.32,},
  13.                             {0, -0.3, 0, -1.28, 0.52,},
  14.                             {-0.3, 0.5, 1.8, -7.3, 5.5,} };
  15.         double b[25];
  16.         setlocale(0, "rus");
  17.         cout<<"Матрица 1"<<endl;
  18.         for (i=0; i<5;i++)
  19.         {
  20.             for (j=0; j<5; j++)
  21.             {
  22.                 cout<<a[i][j]<<"\t\t ";
  23.                 if(a[i][j]>0 && a[i][j]<1)
  24.                 {
  25.                     b[k]=a[i][j];
  26.                     k=k+1;
  27.                 }
  28.             }
  29.             cout<<endl;
  30.         }
  31.         cout<<"Массив №2"<<endl;
  32.         for (i=0; i<k; i++)
  33.         {
  34.             cout<<b[i]<<endl;
  35.             if (b[i]<min)
  36.                 min=b[i];
  37.         }
  38.         cout<<endl;
  39.         cout<<"Минимальный элемент второго массива= "<<min<<endl;
  40.     return 0;
  41.         }
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49. #include "stdafx.h"
  50. #include <iostream>
  51. #include <math.h>
  52. using namespace std;
  53. double func(int a[5][5])
  54. {  
  55.     int i, j;
  56.         double p=0;
  57.     for (i=0; i<5; i++)
  58.         {
  59.             for (j=0; j<5; j++)
  60.             {
  61.             p=p+a[i][j];
  62.             }
  63.         }
  64. return (p);
  65. }
  66. void func2 (int a[5][5])
  67. {
  68. int i, j;
  69. for (i=0;i<5;i++)
  70.     {
  71.         for (j=0;j<5;j++)
  72.         {
  73.             if (a[i][j]<0)
  74.             a[i][j]=0;
  75.         }
  76.     }
  77. }
  78. int _tmain(int argc, _TCHAR* argv[])
  79. {
  80.     int i, j, a[5][5];
  81.     setlocale (0,"rus");
  82.     for (i=0; i<5;i++)
  83.     {
  84.         for (j=0; j<5;j++)
  85.         {
  86.         a[i][j]=-10+rand()%20;
  87.         }
  88.     }
  89.     cout<<"Матрица 1"<<endl;
  90.         for (i=0; i<5;i++)
  91.         {
  92.             for (j=0; j<5; j++)
  93.             {
  94.                 cout<<a[i][j]<<"\t";
  95.             }
  96.             cout<<endl;
  97.         }
  98.         cout<<endl;
  99.         cout<<"Сумма элементов матрицы= "<<func(a)<<endl;
  100.         cout<<endl;
  101.         func2(a);
  102.         cout<<"Матрица 2"<<endl;
  103.         for (i=0; i<5;i++)
  104.         {
  105.             for (j=0; j<5; j++)
  106.             {
  107.                 cout<<a[i][j]<<"\t";
  108.             }
  109.             cout<<endl;
  110.         }  
  111.     return 0;
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement