Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. setlocale(LC_ALL, "Rus");
  8. int n, m;
  9. cout << "кол-во строк: ";
  10. cin >> n;
  11. cout << "кол-во столбцов: ";
  12. cin >> m;
  13. int** arr = new int* [n];
  14. for (int i = 0; i < m; i++)
  15. {
  16. arr[i] = new int[m];
  17. }
  18. cout << "Введите элемент:" << endl;
  19. for (int i = 0; i < n; ++i)
  20. for (int j = 0; j < m; ++j)
  21. {
  22. cout << "a[" << i << ", " << j << "] = ";
  23. cin >> arr[i][j];
  24. }
  25. cout << "Массив:" << endl;
  26. for (int i = 0; i < n; ++i)
  27. {
  28. for (int j = 0; j < m; ++j)
  29. {
  30. cout << "a[" << i << ", " << j << "] = ";
  31. cout << *(*(arr + i) + j) << '\t';
  32. }
  33. cout << '\n';
  34. }
  35. int k;
  36. cout << "Введите k: ";
  37. cin >> k;
  38. if (k < n + m)
  39. {
  40. int summ = 0;
  41. for (int i = 1; i < n; i++)
  42. {
  43. for (int j = 1; j < m; j++)
  44. {
  45.  
  46. if (i + j == k)
  47. {
  48. summ += arr[i][j];
  49. }
  50. }
  51.  
  52. }
  53. cout << "Сумма элементов, чья сумма индексов=" << k << "=" << summ << endl;
  54.  
  55. }
  56. else
  57. {
  58. cout << "False";
  59. }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement