ЯП: С++
#include <iostream>
int main() {
const int N = 5;
int arr[N][N] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25}; // создаем и заполняем двумерный массив 5x5
for (int i = 0; i < N; i++) // выводим на экран 2-мерный массив;
{
for (int j = 0; j < N; j++)
{
std::cout << arr[i][j] << "\t";
}
std::cout << std::endl;
}
std::cout << "Result #1: ";
for (int i = 0; i < N; i++) // вывод в консоль главной диагонали
{
std::cout << arr[i][i] << "\t";
}
std::cout << "\nResult #2: ";
for (int i = 0; i < N; i++) // вывод в консоль побочной диагонали
{
std::cout << arr[i][N - 1 - i] << "\t";
}
return 0;
}
Объяснение:
#include <iostream>
using std::cout;
using std::endl;
#include <cstdlib>
using std::rand;
using std::srand;
#include <ctime>
using std::time;
int main()
{
int a[12];
for(int i = 0; i < 12; i++)
{
a[i] = rand() % 21;
cout << a[i] << ' ';
}
cout << endl;
int temp;
for(int i = 0, j = 11; i < j; i++, j--)
{
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
for(int i = 0; i < 12; i++)
{
cout << a[i] << ' ';
}
cout << endl;
return 0;
}
S:=D+4 { переменной S присваивается значение 10}