--- Python 3.8.3 ---
def MatrixPrint(Matr):
matrixstring = ''
rows = len(Matr)
cols = len(Matr[0])
for row in range(rows):
for col in range(cols):
matrixstring += str(Matr[row][col]) + ' '
matrixstring += '\n'
print(matrixstring)
def main():
n = int(input())
Matr = [[int(i) for i in input().split(maxsplit=n)] for i in range(n)]
for i in range(n):
Matr[i][i], Matr[i][n-i-1] = Matr[i][n-i-1], Matr[i][i]
MatrixPrint(Matr)
if __name__ == "__main__":
main()
Объяснение:
#include <iostream>
int main() {
using namespace std;
setlocale(LC_ALL, "Russian");
int N;
cout << "Введите размерность массива: ";
cin >> N;
int* A = new int[N];
for (int i = 0; i < N; i++)
{
cout << "Заполните [" << i + 1 << "] элемент: ";
cin >> A[i];
}
cout << endl;
cout << A[i] << " ";
int max_index = 0;
for (int i = 1; i < N; i++)
if (A[i] > A[max_index]) {
max_index = i;
cout << "\nНомер локального максимума: " << max_index + 1;
return 0;
--- Python 3.8.3 ---
def MatrixPrint(Matr):
matrixstring = ''
rows = len(Matr)
cols = len(Matr[0])
for row in range(rows):
for col in range(cols):
matrixstring += str(Matr[row][col]) + ' '
matrixstring += '\n'
print(matrixstring)
def main():
n = int(input())
Matr = [[int(i) for i in input().split(maxsplit=n)] for i in range(n)]
for i in range(n):
Matr[i][i], Matr[i][n-i-1] = Matr[i][n-i-1], Matr[i][i]
MatrixPrint(Matr)
if __name__ == "__main__":
main()
Объяснение:
#include <iostream>
int main() {
using namespace std;
setlocale(LC_ALL, "Russian");
int N;
cout << "Введите размерность массива: ";
cin >> N;
int* A = new int[N];
for (int i = 0; i < N; i++)
{
cout << "Заполните [" << i + 1 << "] элемент: ";
cin >> A[i];
}
cout << endl;
for (int i = 0; i < N; i++)
{
cout << A[i] << " ";
}
int max_index = 0;
for (int i = 1; i < N; i++)
{
if (A[i] > A[max_index]) {
max_index = i;
}
}
cout << "\nНомер локального максимума: " << max_index + 1;
return 0;
}