Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <ctime>
- #include <cstdlib>
- using namespace std;
- int main()
- {
- srand(time(NULL));
- int n;
- int b[10][10];
- int Vv;
- cout << "Введите 1 если хотите ввод с клавиатуры, 2 если случайными часлами в диапозоне";
- cin >> Vv;
- cout << "Введите размерность матсрицы";
- cin >> n;
- double k=0;
- for (int i=0; i<n; i++)
- for(int j=0; j<n; j++)
- {
- if(Vv==1)
- cin >> b[i][j];
- else b[i][j] = rand() % 301 - 100;
- if (i==j && b[i][j]<0)
- k=1;
- }
- int j=0;
- if (k==0)
- {
- double sum=0;
- for (int i=0; i<n; i++)
- {
- sum+= b[i][i]*b[i][n-1-j];
- j++;
- }
- cout << sum;
- }
- else
- {
- int a[10];
- for (int i=0; i<n; i++)
- {
- a[i] = b[i][n-1-j];
- j++;
- }
- j=0;
- for(int i=0; i<n; i++)
- {
- for (int j_=n-1; j_>i; j_--)
- {
- if (a[j_] < a[j_-1])
- {
- k=a[j_];
- a[j_]=a[j_-1];
- a[j_-1]=k;
- }
- }
- b[i][n-1-j] = a[i];
- j++;
- }
- for (int i=0; i<n; i++)
- {
- for(int j=0; j<n; j++)
- {
- cout << b[i][j] << " ";
- }
- cout << endl;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement