//Видимо, это одна задача, так как "изменения" во второй не указаны //Pascal ABC.NET v3.1 сборка 1172
Const n=20;
Var ar:array[1..n] of integer; i:integer; begin randomize; writeln('First array:'); for i:=1 to n do begin ar[i]:=random(10)-3; write(ar[i]:4); if ar[i]>0 then ar[i]:=ar[i]*2 else ar[i]:=0; end; writeln; writeln('Final array:'); for i:=1 to n do write(ar[i]:4); end.
#include <iostream>
#include <iomanip>
#include <vector>
#include <ctime>
int main()
{
using namespace std;
const int n = 5;
int A[n][n];
int D[n][n];
vector<int> B(n);
vector<int> C(n);
vector<int> S(n); //результирующий вектор
//как-нибудь заполняем исходные матрицы и вектора
srand(time(0));
for (int i = 0; i < n; ++i)
{
for (int j = 0; j < n; ++j)
{
A[i][j] = rand() % (n * n) - n * n / 2;
D[i][j] = rand() % (n * n) - n * 2;
}
B[i] = rand() % (n * n) - n;
C[i] = rand() % (n * n) - n * n + n;
}
//выведем исходные данные на экран
cout << "matrix A:\n";
for (int i = 0; i < n; ++i)
{
for (int j = 0; j < n; ++j)
cout << setw(5) << A[i][j];
cout << endl;
}
cout << "\nmatrix D:\n";
for (int i = 0; i < n; ++i)
{
for (int j = 0; j < n; ++j)
cout << setw(5) << D[i][j];
cout << endl;
}
cout << "\nvector B:\n";
for (int i = 0; i < n; ++i)
cout << setw(5) << B[i] << endl;
cout << "\nvector C:\n";
for (int i = 0; i < n; ++i)
cout << setw(5) << C[i] << endl;
//вычислим требуемое
for (int i = 0; i < n; ++i)
{
S[i] = 0;
for (int j = 0; j < n; ++j)
S[i] += D[i][j] * C[j];
S[i] += 3 * B[i];
}
//выведем результат на экран
cout << "\nvector S = D * C + 3 * B:\n";
for (int i = 0; i < n; ++i)
cout << setw(5) << S[i] << endl;
return 0;
}