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

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

Відповідь:
#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;
}



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.


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


Топ вопросов за вчера в категории Информатика
Последние заданные вопросы в категории Информатика
-
Математика
-
Литература
-
Алгебра
-
Русский язык
-
Геометрия
-
Английский язык
-
Химия
-
Физика
-
Биология
-
Другие предметы
-
История
-
Обществознание
-
Окружающий мир
-
География
-
Українська мова
-
Информатика
-
Українська література
-
Қазақ тiлi
-
Экономика
-
Музыка
-
Право
-
Беларуская мова
-
Французский язык
-
Немецкий язык
-
МХК
-
ОБЖ
-
Психология
-
Физкультура и спорт
-
Астрономия
-
Кыргыз тили
-
Оʻzbek tili