Advertisement
Guest User

Untitled

a guest
May 19th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. #include <iostream>
  2. #include <ctime>
  3. #include <cstdlib>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. srand(time(NULL));
  10. int n;
  11. int b[10][10];
  12. int Vv;
  13.  
  14. cout << "Введите 1 если хотите ввод с клавиатуры, 2 если случайными часлами в диапозоне";
  15. cin >> Vv;
  16. cout << "Введите размерность матсрицы";
  17. cin >> n;
  18.  
  19. double k=0;
  20.  
  21. for (int i=0; i<n; i++)
  22. for(int j=0; j<n; j++)
  23. {
  24. if(Vv==1)
  25. cin >> b[i][j];
  26. else b[i][j] = rand() % 301 - 100;
  27.  
  28. if (i==j && b[i][j]<0)
  29. k=1;
  30.  
  31. }
  32.  
  33. int j=0;
  34. if (k==0)
  35. {
  36. double sum=0;
  37.  
  38. for (int i=0; i<n; i++)
  39. {
  40. sum+= b[i][i]*b[i][n-1-j];
  41. j++;
  42. }
  43. cout << sum;
  44. }
  45. else
  46. {
  47. int a[10];
  48.  
  49. for (int i=0; i<n; i++)
  50. {
  51. a[i] = b[i][n-1-j];
  52. j++;
  53. }
  54. j=0;
  55. for(int i=0; i<n; i++)
  56. {
  57.  
  58. for (int j_=n-1; j_>i; j_--)
  59. {
  60. if (a[j_] < a[j_-1])
  61. {
  62. k=a[j_];
  63. a[j_]=a[j_-1];
  64. a[j_-1]=k;
  65. }
  66. }
  67.  
  68. b[i][n-1-j] = a[i];
  69. j++;
  70. }
  71.  
  72. for (int i=0; i<n; i++)
  73. {
  74. for(int j=0; j<n; j++)
  75. {
  76. cout << b[i][j] << " ";
  77. }
  78. cout << endl;
  79. }
  80. }
  81.  
  82. return 0;
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement