Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- int main()
- {
- setlocale(LC_ALL, "Rus");
- int n, m;
- cout << "кол-во строк: ";
- cin >> n;
- cout << "кол-во столбцов: ";
- cin >> m;
- int** arr = new int* [n];
- for (int i = 0; i < m; i++)
- {
- arr[i] = new int[m];
- }
- cout << "Введите элемент:" << endl;
- for (int i = 0; i < n; ++i)
- for (int j = 0; j < m; ++j)
- {
- cout << "a[" << i << ", " << j << "] = ";
- cin >> arr[i][j];
- }
- cout << "Массив:" << endl;
- for (int i = 0; i < n; ++i)
- {
- for (int j = 0; j < m; ++j)
- {
- cout << "a[" << i << ", " << j << "] = ";
- cout << *(*(arr + i) + j) << '\t';
- }
- cout << '\n';
- }
- int k;
- cout << "Введите k: ";
- cin >> k;
- if (k < n + m)
- {
- int summ = 0;
- for (int i = 1; i < n; i++)
- {
- for (int j = 1; j < m; j++)
- {
- if (i + j == k)
- {
- summ += arr[i][j];
- }
- }
- }
- cout << "Сумма элементов, чья сумма индексов=" << k << "=" << summ << endl;
- }
- else
- {
- cout << "False";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement