Advertisement
mercMatvey4

Untitled

Feb 16th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <ctime>
  4. #include <iomanip>
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. setlocale(LC_ALL,"");
  10. srand(time(0));
  11. int n;
  12. cin >> n;
  13. int arr[n][n];
  14. float sum1(0),sum2(0),count1(0),count2(0);
  15. for (int i = 0; i < n; i++)
  16. for (int j = 0; j < n; j++)
  17. arr[i][j] = rand()%10 - 4;
  18. cout << "Исходная квадратная матрица : \n";
  19. for (int i = 0; i < n; i++)
  20. {
  21. for (int j = 0; j < n; j++)
  22. {
  23. cout << setw(3) << arr[i][j] ;
  24. }
  25. cout << endl;
  26. }
  27. for (int i = 0; i < n; i++)
  28. for (int j = 0; j < n; j++)
  29. {
  30. if (i == j && arr[i][j]>0)
  31. {
  32. sum1 += arr[i][j];
  33. count1++;
  34. }
  35. if (j == n-1-i && arr[i][j]<0)
  36. {
  37. sum2 += arr[i][j];
  38. count2++;
  39.  
  40. }
  41. }
  42. cout << "Среднее арифметическое положительных эл-тов главной диагонали : " << sum1/count1;
  43. cout << "\nСреднее арифметическое отрицательных эл-тов побочной диагонали : " << sum2/count2;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement