Предмет: Информатика, автор: danilmalyar03

Кто знает как сделать?

Приложения:

Ответы

Автор ответа: Koljisto
0

Begin

 var B:=ArrRandomReal(ReadInteger('Введите N'),-30,30);

 B.Println;

 var sum_positive:=B.where(n->(n>0)).Sum;

 var if_b:=B.where(n->(n>5) and (n<7)).Count;

 println(sum_positive,if_b);

 var min:=B.MinBy(p->abs(p));

 var max:=B.MaxBy(p->abs(p));

 var pow:real:=1;

 for var i:=B.FindIndex(p-> p=min) to B.FindIndex(p-> p=max) do

   pow*=B[i];

 println(min,max);

 println(pow);

end.


Аноним: Здравствуйте, можете помочь написать программу на С++?
Автор ответа: shpaler2k16
0

Ответ:

#include <iostream>

#include <ctime>

using std::cout;

using std::cin;

using std::swap;

double* get_mas(int size)

{

srand(time(NULL));

double* mas = new double[size];

for (int i = 0; i < size; i++)

 mas[i] = rand() / (double)0x7FFF * 60 - 30;//0x7FFF -> положительный предел для float, больше нет необходимости

for (int i = 0; i < size; i++)

 cout <<'[' << i << "] = " << mas[i] << '\n';

cout << '\n';

return mas;

}

double sum_positive(double *mas, int size)

{

double res = 0;

for (int i = 0; i < size; i++)

 if (mas[i] > 0)

  res += mas[i];

return res;

}

double condition(double *mas, int size)

{

int res = 0;

for (int i = 0; i < size; i++)

 if (mas[i] < 7.0 && mas[i] > 5.0)

  res++;

return res;

}

double multiplication(double *mas, int size)

{

double min = abs(mas[0]), max = abs(mas[0]);

int minIndex = 0, maxIndex = 0;

for (int i = 1; i < size; i++)

{

 if (abs(mas[i]) <= min)

 {

  min = abs(mas[i]);

  minIndex = i;

  continue;

 }

 if (abs(mas[i]) >= max)

 {

  max = abs(mas[i]);

  maxIndex = i;

 }

}

if (minIndex - maxIndex == 0)

 return 0.0;

int res = 1.0;

if (minIndex > maxIndex)

 swap(minIndex, maxIndex);

cout <<"MIN: " << minIndex << "; MAX: " << maxIndex << ";\n";

for (int i = minIndex; i < maxIndex; i++)

 res *= mas[i];

return res;

}

int main()

{

int size;

cout << "SIZE: ";

cin >> size;

double* mas = get_mas(size);

cout << "1) " << sum_positive(mas, size) << '\n';

cout << "2) " << condition(mas, size) << '\n';

cout << "3) " << multiplication(mas, size) << '\n';

cin.get(); cin.get();

}

Объяснение:

Похожие вопросы
Предмет: Математика, автор: katyanovosyolova