Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.38 KB | None | 0 0
  1.  
  2. #include "pch.h"
  3. #include <iostream>
  4. #include <ctime>
  5.  
  6. int const k = 3;
  7. int num[k][k];
  8. int newNum[k][k];
  9. using namespace std;
  10.  
  11. void input() {
  12.     for (int i = 0; i < k; i++) {
  13.         for (int j = 0; j < k; j++) {
  14.             num[i][j] = -7 + rand() % 15;
  15.         }
  16.     }
  17. }
  18.  
  19. void output() {
  20.     for (int i = 0; i < k; i++) {
  21.         for (int j = 0; j < k; j++) {
  22.             cout << num[i][j] << " ";
  23.         }
  24.         cout << endl;
  25.     }
  26.     cout << endl;
  27. }
  28.  
  29. void sum() {
  30.     int s = 0;
  31.     for (int i = 0; i < k; i++) {
  32.         for (int j = 0; j < k; j++) {
  33.             s += num[i][j];
  34.         }
  35.     }
  36.     cout << "sum = " << s;
  37. }
  38.  
  39.  
  40. int miniFact(int n) {
  41.     if (n == 0) {
  42.         return 1;
  43.     }
  44.     else {
  45.         return n * miniFact(n - 1);
  46.     }
  47. }
  48.  
  49. void fact() {
  50.     for (int i = 0; i < k; i++) {
  51.         for (int j = 0; j < k; j++) {
  52.             newNum[i][j] = miniFact(abs(num[i][j]));
  53.             cout << newNum[i][j] << " ";
  54.         }
  55.         cout << endl;
  56.     }
  57. }
  58.  
  59. void kolvo() {
  60.     int n = k - 1;
  61.     int kol1 = 0;
  62.     int kol2 = 0;
  63.    
  64.     for (int i = 0; i < k - 1; i++) {
  65.         for (int j = 0; j < n; j++) {
  66.             if (num[i][j] > 0) {
  67.                 kol1++;
  68.             }
  69.         }
  70.         cout << endl;
  71.         n--;
  72.     }
  73.     cout << endl;
  74.     n = 1;
  75.     for (int i = k-1; i > 0; i--) {
  76.         for (int j = n; j < k; j++) {
  77.             if (num[i][j] > 0) {
  78.                 kol2++;
  79.             }
  80.         }
  81.         cout << endl;
  82.         n++;
  83.     }
  84.     cout << "Verh = " << kol1 << " Niz = " << kol2 << endl;
  85. }
  86.  
  87. int main()
  88. {
  89.     srand(time(NULL));
  90.     input();
  91.     output();
  92.     kolvo();
  93.     fact();
  94.     sum();
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement