Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <windows.h>
  4. #include <cstdlib>
  5. #include <time.h>
  6. using namespace std;
  7. int main(){
  8. setlocale(0,"rus");
  9. SetConsoleOutputCP(1251);
  10. SetConsoleCP(1251);
  11. srand(time(0));
  12. int n = 5;
  13. int a[5][5];
  14. int k;
  15. float s1, s2, p;
  16. cout << "Исходная матрица:" << endl;
  17. for (int i = 0; i < n; i++)
  18. {
  19. cout << endl;
  20. for (int j = 0; j < n; j++)
  21. {
  22. a[i][j] = -n / 2 + rand() % (n * n);
  23. cout << a[i][j] ;
  24. }
  25. }
  26. cout<<endl;
  27. cout << "Введите номер строки: " << endl;
  28. cin >> k;
  29. if (k < 1 || k > 5)
  30. {
  31. return -1;
  32. }
  33. k -= 1;
  34. s1 = 0;
  35. s2 = 0;
  36. for (int j = 0; j < n; j++)
  37. {
  38. s1 = s1 + a[k][j];
  39. s2 = s2 + a[j][j];
  40. }
  41. cout << "Сумма в строке: " << s1 << ", Сумма диагонали: " << s2 << endl;
  42. cout << "Произведение: " << s1 * s2 << endl;
  43. return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement