begin
var arr := arrRandom(10, -10, 10);
write('Исходный массив: ');
foreach var e in arr do write(e : 4);
writeln();
writeln('Сумма положительных элементов: ',
arr.Where(e -> e >= 0).Sum(e -> e));
writeln('Сумма чётных элементов: ',
arr.Where(e -> e mod 2 = 0).Sum(e -> e));
writeln('Сумма первых 5 элементов: ',
arr.Take(5).Sum(e -> e));
end.
Напишем программу, которая будет считать сумму всех чисел от 1 до 1000.
<span><span>#include <iostream>
</span>
using namespace std;<span>
int main()
</span>{
int i; // счетчик цикла
int sum = 0; //сумма чисел от 1 до 1000.
setlocale(0, "");
for (i = 1; i <= 1000; i++) // задаем начальное значение 1, конечное 1000 и задаем шаг цикла - 1.
{
sum = sum + i;
}
cout << "Сумма чисел от 1 до 1000 = " << sum <<
endl;
return 0;
}</span>
6)
1-b; 2-d; 3-a; 4-c.
7)На C++
#include <iostream>
using namespace std;
int main(void)
{
int age = 0;
cout << "Input your age: ";
cin >> age;
if (age > 18 || age == 18)
cout << "You have the right to vote." << endl;
else
cout << "You don't have the right to vote." << endl;
system("pause");
return 0;
}