1)
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
void print_matrix(int **matrix, const int n)
{
for (int jjj = 0; jjj < n; jjj++)
for (int kkk = 0; kkk < n; kkk++)
cout << matrix[jjj][kkk] << " ";
cout << endl;
};
}
void fill_matrix(int **matrix, const int n)
int min = 0;
int max = 100;
matrix[jjj][kkk] = rand() % (max - min + 1) + min;
void transform_matrix(int **matrix1, int **matrix2, const int n)
int xswap = rand() % n;
int yswap = rand() % n;
cout << "\n"
<< xswap << " " << yswap << endl;
for (int jjj = xswap; jjj < n; jjj++)
matrix2[jjj][kkk] = matrix1[jjj - xswap][kkk];
for (int jjj = 0; jjj < xswap; jjj++)
matrix2[jjj][kkk] = matrix1[jjj + n - xswap][kkk];
for (int kkk = yswap; kkk < n; kkk++)
matrix2[jjj][kkk] = matrix1[jjj][kkk - yswap];
for (int kkk = 0; kkk < yswap; kkk++)
matrix2[jjj][kkk] = matrix1[jjj][kkk + n - yswap];
int main()
srand(time(0));
const int n = 5;
int **matrix1 = new int *[n];
matrix1[jjj] = new int[n];
fill_matrix(matrix1, n);
print_matrix(matrix1, n);
int **matrix2 = new int *[n];
matrix2[jjj] = new int[n];
transform_matrix(matrix1, matrix2, n);
print_matrix(matrix2, n);
begin
var mas:=ArrRandom(20,-99,99); mas.Println;
var a:=mas[0:10]; var b:=mas[10:20];
Writeln('количество положительных элементов=',a.Where(t->t>0).Count);
Writeln('количество отрицательных элементов=',b.Where(t->t<0).Count);
end.
это как учат в школе :->
var
i,k,l:integer;
mas:Array[1..20] of integer;
begin
randomize;
for i:=1 to 20 do
mas[i]:=random(-99,99);
for i:=1 to 10 do
if mas[i]>0 then
k:=k+1;
for i:=11 to 20 do
if mas[i]>0 then
l:=l+1;
Writeln('количество положительных элементов=',k);
Writeln('количество отрицательных элементов=',l);
end.
1)
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
void print_matrix(int **matrix, const int n)
{
for (int jjj = 0; jjj < n; jjj++)
{
for (int kkk = 0; kkk < n; kkk++)
cout << matrix[jjj][kkk] << " ";
cout << endl;
};
}
void fill_matrix(int **matrix, const int n)
{
int min = 0;
int max = 100;
for (int jjj = 0; jjj < n; jjj++)
for (int kkk = 0; kkk < n; kkk++)
matrix[jjj][kkk] = rand() % (max - min + 1) + min;
}
void transform_matrix(int **matrix1, int **matrix2, const int n)
{
int xswap = rand() % n;
int yswap = rand() % n;
cout << "\n"
<< xswap << " " << yswap << endl;
for (int jjj = xswap; jjj < n; jjj++)
for (int kkk = 0; kkk < n; kkk++)
matrix2[jjj][kkk] = matrix1[jjj - xswap][kkk];
for (int jjj = 0; jjj < xswap; jjj++)
for (int kkk = 0; kkk < n; kkk++)
matrix2[jjj][kkk] = matrix1[jjj + n - xswap][kkk];
for (int jjj = 0; jjj < n; jjj++)
for (int kkk = yswap; kkk < n; kkk++)
matrix2[jjj][kkk] = matrix1[jjj][kkk - yswap];
for (int jjj = 0; jjj < n; jjj++)
for (int kkk = 0; kkk < yswap; kkk++)
matrix2[jjj][kkk] = matrix1[jjj][kkk + n - yswap];
}
int main()
{
srand(time(0));
const int n = 5;
int **matrix1 = new int *[n];
for (int jjj = 0; jjj < n; jjj++)
matrix1[jjj] = new int[n];
fill_matrix(matrix1, n);
print_matrix(matrix1, n);
int **matrix2 = new int *[n];
for (int jjj = 0; jjj < n; jjj++)
matrix2[jjj] = new int[n];
transform_matrix(matrix1, matrix2, n);
cout << endl;
print_matrix(matrix2, n);
}