#include <iostream>
#include<stdlib.h>
/*
В прямоугольной целочисельной матрице упорядочить элементы, которые размещены на главной диагонале по убыванию
*/
using namespace std;
int main() {
setlocale(LC_ALL,"rus");
cout << "Masiv do sortirovki "<< endl << endl;
int mas[5][5];
for(int i=0; i<5; i++){
for(int j=0; j<5; j++){
mas[i][j]=-10+rand()%90;
cout<<mas[i][j]<<" ";
}
cout << endl;
}
cout << endl << endl;
cout << "Masiv posle sortirovki "<< endl << endl;
/* сортировку тут нужно провести */
for(int i=0; i<5; i++){
for(int j=0; j<5; j++){
cout<<mas[i][j]<<" ";
}
cout << endl;
}
cout << endl << endl;
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;
}
Python
from random import randint
def getH(s):
while s>10:
s=s//10
return s
n=int(input('Введите размер массива: '))
a=[0]*n
b=0
for i in range(0, n-1):
a[i]=randint(0, 1000)
if getH(a[i])==8:
b+=1
print(a)
print('Элементов начинающихся с 8 =',b)
# задание 2
a=sorted(a)
i=1
b=1
print('3 минимальных элемента')
print(a[0])
while b<3 and b<n:
if a[i]!=a[i-1]:
print(a[i])
b+=1
i+=1
>>Введите размер массива: 45
[464, 937, 662, 266, 915, 535, 690, 663, 441, 791, 979, 831, 853, 92, 411, 429, 845, 949, 116, 178, 129, 434, 824, 802, 643, 41, 612, 654, 361, 503, 141, 290, 13, 401, 157, 55, 376, 960, 856, 869, 194, 913, 447, 639, 0]
Элементов начинающихся с 8 = 7
3 минимальных элемента
0
13
41