Предмет: Информатика, автор: 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();

}

Объяснение:

Похожие вопросы
Предмет: Английский язык, автор: bradulmark
Control of Writing (7th form)

I variant
Complete the sentences with up, after, for, forward to.1. I looked _____ her.

2. Who will look_____your little brother.

3. If you don't know the meaning of a word, look it_____in a good dictionary.

4. Every year the children look ______ the holidays coming.

2.Complete the sentences using Past Simple or Past Continuous .
Father _____(watch) TV at ten o’clock yesterday.When I ______(come) home, Kate_____(play) the piano.They_____ (translate) a difficult test yesterday.When I _____(open) the door, my friends_____(sit) around the table.I_____(go) to the theatre yesterday.Complete the sentences. 1.If you ____ (drop) a book, it falls.

2. When Jill ____ (eat) fish, she is sick.

3. If it _____(rain), I ____(not go) to the park.

4. If I_____(get) this job, I_____(earn) a lot of money.

II variant
Complete the sentences with after, for, up, forward to. 1.I’m so looking ______ it.

2. Who will look_____your little sister.

3. I’m looking_____my bag.

4. I looked it _____in the dictionary.
Complete the sentences using Past Simple or Past Continuous .When I _____(go) to school, I ______(meet) my friend.They ______(play) in the yard in the evening yesterday.I _____ (play) the piano at five o’clock yesterday.He _____(read) a newspaper, when I_____(come) in.The train_____(start) at fifteen minutes to ten.Complete the sentences. 1. If you _____ (heat) water to 100 Celsius, it boils.

2. When I _______(to cook) salads, I use only olive oil.

3. If I______(see) Mary, I ______(tell) her.

4. If I _____(go) to London, I _____ (see) the Tower of London.