// PascalABC.NET 3.1, сборка 1179 от 29.02.2016 procedure GetProdNeg(a:array of integer; var p:real); // произведение отрицательных элементов begin p:=a.Where(x->x<0).Aggregate(1.0,(p,e)->p*e) end;
function IsPrime(n:integer):boolean:= Range(2,Round(sqrt(n))).All(i->n mod i<>0);
procedure ArrPrime(n:integer; var a:array of integer); // массив простых чисел не больших n begin a:=Range(2,n).Where(i->IsPrime(i)).ToArray end;
begin var n:=ReadInteger('n='); var a:=ArrRandom(n,-50,50); a.Println; var r:real; GetProdNeg(a,r); Writeln('Произведение ',r); n:=ReadInteger('n='); var b:array of integer; ArrPrime(n,b); b.Println end.
#include <iostream>
#include <vector>
using namespace std;
float summatrix(vector < vector<float>>& v) {
float s=0;
for (int i = 0; i < v.size(); i++) {
for (int j = 0; j < v[i].size(); j++) {
if (j > i) s += v[i][j];
}
}
return s;
}
float mulmatrix(vector < vector<float>>& v) {
float s = 1;
for (int i = 0; i < v.size(); i++) {
for (int j = 0; j < v[i].size(); j++) {
if (i > j) s *= v[i][j];
}
}
return s;
}
int main()
{
//создадим матрицу 5 на 5 и заполним ее случайными числами
vector < vector<float>> v1(5,vector<float>(5));
for (auto& it1 : v1) {
for (auto& it2 : it1) {
it2 = float(rand()%100+1)/10.0;
}
}
//создадим матрицу 8 на 8 и заполним ее случайными числами
vector < vector<float>> v2(8, vector<float>(8));
for (auto& it1 : v2) {
for (auto& it2 : it1) {
it2 = float(rand()%100+1) / 10.0;
}
}
//Выведем матрицы на экран
for (auto& it1 : v1) {
for (auto& it2 : it1) {
cout << it2 << " ";
}
cout << endl;
}
cout << endl;
for (auto& it1 : v2) {
for (auto& it2 : it1) {
cout << it2 << " ";
}
cout << endl;
}
cout << endl;
cout << "sum v1=" << summatrix(v1)<<endl;
cout << "sum v2=" << summatrix(v2) << endl;
cout << "mul v1=" << mulmatrix(v1) << endl;
cout << "mul v2=" << mulmatrix(v2) << endl;
}
Объяснение: