Вопрос задан 16.06.2023 в 18:04. Предмет Информатика. Спрашивает Лютанов Дима.

Вариант 1-2. Создать массив А из десяти целых чисел, принадлежащих промежутку [0;15). Вывести

полученный массив на экран. Посчитать s - сумму элементов массива, значение которых меньше 5.
0 0
Перейти к ответам

Ответы на вопрос

Внимание! Ответы на вопросы дают живые люди. Они могут содержать ошибочную информацию, заблуждения, а также ответы могут быть сгенерированы нейросетями. Будьте внимательны. Если вы уверены, что ответ неверный, нажмите кнопку "Пожаловаться" под ответом.
Отвечает Чижов Вадим.

Відповідь:

#include <iostream>

#include <cstdlib>

#include <time.h>

using namespace std;

void randarr(int *arr,const int size){

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

 arr[i] = rand() % 15 + 0;

}

}

void printarr(int *arr,const int size){

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

 cout << arr[i] << " ";

}

}

int sumel(int *arr,const int size){

int S = 0;

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

 if(arr[i] < 5){

  S += arr[i];

 }

}

return S;

}

const int size = 10;

int main(){

srand(time(NULL));

setlocale(LC_ALL , "Rus");

int arr[size];

randarr(arr,size);

printarr(arr,size);

cout << "\nСумма елементов массива которые < 5 = " << sumel(arr,size) << endl;

return 0;

}

0 0
Отвечает нейросеть ChatGpt. Будьте внимательны, ответы нейросети могут содержать ошибочные или выдуманные данные.

Creating and Displaying an Array in Pascal

To create an array A of ten integers belonging to the range [0;15) and display the array, you can use the following Pascal code:

```pascal program Variant1;

var A: array[1..10] of integer; i: integer;

begin for i := 1 to 10 do begin A[i] := Random(15); // Generate random integers in the range [0;15) writeln(A[i]); // Display the elements of the array end; end. ```

Calculating the Sum of Elements Less Than 5

To calculate the sum of elements in the array A whose values are less than 5, you can use the following Pascal code:

```pascal program Variant1;

var A: array[1..10] of integer; i, s: integer;

begin s := 0; // Initialize the sum for i := 1 to 10 do begin A[i] := Random(15); // Generate random integers in the range [0;15) if A[i] < 5 then s := s + A[i]; // Add the element to the sum if it's less than 5 end; writeln('The sum of elements less than 5 is: ', s); // Display the sum end. ```

Note: The above Pascal code uses the `Random` function to generate random integers in the specified range.

0 0

Похожие вопросы

Топ вопросов за вчера в категории Информатика

Последние заданные вопросы в категории Информатика

Задать вопрос