Advertisement
LabiinfaCibGyti

laba10+11.1

Jan 9th, 2020
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.05 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <math.h>
  4. using namespace std;
  5. double func(int a[5][5])
  6. {
  7.     int i, j;
  8.     double p = 0;
  9.     for (i = 0; i < 5; i++)
  10.     {
  11.         for (j = 0; j < 5; j++)
  12.         {
  13.             if (a[i][j]>1 && a[i][j]<5)
  14.                 p++;
  15.         }
  16.     }
  17.     return (p);
  18. }
  19. void func2(int a[5][5])
  20. {
  21.     int i, j, x;
  22.     for (i = 0; i < 5; i++)
  23.     {
  24.         for (j = i; j < 5; j++)
  25.         {
  26.             x = a[i][j];
  27.             a[i][j] = a[j][i];
  28.             a[j][i] = x;
  29.         }
  30.     }
  31. }
  32. int main()
  33. {
  34.     int i, j, a[5][5];
  35.     setlocale(LC_ALL, "");
  36.     for (i = 0; i < 5; i++)
  37.     {
  38.         for (j = 0; j < 5; j++)
  39.         {
  40.             a[i][j] = -10 + rand() % 20;
  41.         }
  42.     }
  43.     cout << "Матрица 1" << endl;
  44.     for (i = 0; i < 5; i++)
  45.     {
  46.         for (j = 0; j < 5; j++)
  47.         {
  48.             cout << a[i][j] << "\t";
  49.         }
  50.         cout << endl;
  51.     }
  52.     cout << endl;
  53.     cout << "Кол-во элементов в промежутке (1;5)= " << func(a) << endl;
  54.     cout << endl;
  55.     func2(a);
  56.     cout << "Матрица 2" << endl;
  57.     for (i = 0; i < 5; i++)
  58.     {
  59.         for (j = 0; j < 5; j++)
  60.         {
  61.             cout << a[i][j] << "\t";
  62.         }
  63.         cout << endl;
  64.     }
  65.     return 0;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement