Advertisement
Daniel_leinaD

4.2 Дмитрий Засов

Jan 25th, 2023
1,302
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.86 KB | None | 0 0
  1. #include <iostream>
  2. #include <clocale>
  3. #include <math.h>
  4. #include <iomanip>
  5. using namespace std;
  6.  
  7. const int n = 6;
  8.  
  9. int f(int x[n][n]){
  10.   int pol = 0, otr = 0;
  11.   for (int i = 0; i < n; i++){
  12.       cout << '\n';
  13.     for (int j =  n-i-1; j < n; j++){
  14.       if (x[i][j] < 0){
  15.         otr++;
  16.         cout << "отр: " << x[i][j] << '\n';
  17.       }
  18.       if (x[i][j] > 0){
  19.         pol++;
  20.         cout << "пол: " << x[i][j] << '\n';
  21.       }
  22.     }
  23.   }
  24.   cout << '\n' << "Кол-во отрицательных = " << otr;
  25.   cout << '\n' << "Кол-во положительных = " << pol;
  26.   cout << '\n';
  27.   return 0;
  28. }
  29.  
  30.  
  31. int main(){
  32.   int a[n][n];
  33.   for (int i = 0; i < n; i++){
  34.     cout << '\n';
  35.     for (int j = 0; j < n; j++){
  36.       a[i][j] = rand()%100 - 50;
  37.       cout << setw(4) << a[i][j];
  38.     }
  39.   }
  40.  
  41.   cout << '\n' <<  f(a);
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement