Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <ctime>
- #include <iomanip>
- using namespace std;
- int main()
- {
- setlocale(LC_ALL,"");
- srand(time(0));
- int n;
- cin >> n;
- int arr[n][n];
- float sum1(0),sum2(0),count1(0),count2(0);
- for (int i = 0; i < n; i++)
- for (int j = 0; j < n; j++)
- arr[i][j] = rand()%10 - 4;
- cout << "Исходная квадратная матрица : \n";
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < n; j++)
- {
- cout << setw(3) << arr[i][j] ;
- }
- cout << endl;
- }
- for (int i = 0; i < n; i++)
- for (int j = 0; j < n; j++)
- {
- if (i == j && arr[i][j]>0)
- {
- sum1 += arr[i][j];
- count1++;
- }
- if (j == n-1-i && arr[i][j]<0)
- {
- sum2 += arr[i][j];
- count2++;
- }
- }
- cout << "Среднее арифметическое положительных эл-тов главной диагонали : " << sum1/count1;
- cout << "\nСреднее арифметическое отрицательных эл-тов побочной диагонали : " << sum2/count2;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement