Вопрос задан 05.12.2023 в 14:29. Предмет Информатика. Спрашивает Ященко Владимир.

ДАЮ 70 БАЛЛОВ 2. Создать двумерный массив В размерностью 4*3, состоящий из целых чисел в

диапазоне от -5 до 5. Вывести массив на экран. Найти сумму его четных элементов. 3. Создать двумерный массив С размерностью 5*5, состоящий из целых чисел в диапазоне от -10 до 10. Вывести массив на экран. Найти сумму элементов в последнем столбце. Найти количество четных элементов в третьей строке. 4. В массиве С(5*3) целых чисел из диапазона [-5;12] вывести сумму нечетных элементов четвертой строки.
0 0
Перейти к ответам

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

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

Задание 2:

program prog;

var

b:array[1..4,1..3] of integer;

i,j,sum:integer;

begin

   sum:=0;

   for i:=1 to 4 do begin

       for j:=1 to 3 do begin

           b[i,j]:=random(-11)+5;

           write(b[i,j]:2, ' ');

           if b[i,j] mod 2 = 0 then sum:=sum+b[i,j];

       end;

       writeln();

   end;

   write('Сумма всех чётных чисел массива равна: ', sum);

end.

Задание 3:

program prog;

var

c:array[1..5,1..5] of integer;

i,j,sum,count:integer;

begin

   sum:=0;

   count:=0;

   for i:=1 to 5 do begin

       for j:=1 to 5 do begin

           c[i,j]:=random(-21)+10;

           write(c[i,j]:3, ' ');

           if j=5 then sum:=sum+c[i,j];

           if (i=3) and (c[i,j] mod 2 = 0) then count:=count+1;

       end;

       writeln();

   end;

   writeln('Сумма элементов последнего столбца массива равна: ', sum);

   writeln('Количество всех чётных чисел в третьей строке массива равна: ', count);

end.

Задание 4:

program prog;

var

c:array[1..5,1..3] of integer;

i,j,sum:integer;

begin

   sum:=0;

   for i:=1 to 5 do begin

       for j:=1 to 3 do begin

           c[i,j]:=random(-18)+12;

           write(c[i,j]:3, ' ');

           if (i=4) and (c[i,j] mod 2 <> 0) then sum:=sum+c[i,j];

       end;

       writeln();

   end;

   writeln('Сумма всех нечётных чисел в четвёртой строке массива равна: ', sum);

end.

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

Task 2: Creating a 4x3 Array and Finding the Sum of Even Elements

To create a 4x3 array consisting of integers in the range from -5 to 5 and find the sum of its even elements, you can follow these steps:

1. Declare a 4x3 array named `array1` of type `int`. 2. Use nested loops to iterate over each element of the array. 3. Inside the loops, generate a random integer in the range from -5 to 5 and assign it to the current element. 4. After filling the array, iterate over each element again and check if it is even. 5. If an element is even, add it to a variable named `sumEven`. 6. Finally, print the array and the value of `sumEven`.

Here's an example code snippet in C++ that accomplishes this task:

```cpp #include #include #include

int main() { // Declare the array int array1[4][3];

// Seed the random number generator std::srand(std::time(0));

// Fill the array and calculate the sum of even elements int sumEven = 0; for (int i = 0; i < 4; i++) { for (int j = 0; j < 3; j++) { // Generate a random integer in the range from -5 to 5 array1[i][j] = std::rand() % 11 - 5;

// Check if the element is even if (array1[i][j] % 2 == 0) { sumEven += array1[i][j]; } } }

// Print the array std::cout << "Array1:" << std::endl; for (int i = 0; i < 4; i++) { for (int j = 0; j < 3; j++) { std::cout << array1[i][j] << " "; } std::cout << std::endl; }

// Print the sum of even elements std::cout << "Sum of even elements: " << sumEven << std::endl;

return 0; } ```

Please note that the random number generator is seeded with the current time to ensure different random values each time the program is run. The `% 11 - 5` expression is used to generate random integers in the range from -5 to 5.

Task 3: Creating a 5x5 Array and Finding the Sum of Elements in the Last Column and the Number of Even Elements in the Third Row

To create a 5x5 array consisting of integers in the range from -10 to 10 and find the sum of elements in the last column as well as the number of even elements in the third row, you can follow these steps:

1. Declare a 5x5 array named `array2` of type `int`. 2. Use nested loops to iterate over each element of the array. 3. Inside the loops, generate a random integer in the range from -10 to 10 and assign it to the current element. 4. After filling the array, iterate over each element in the last column and calculate their sum, storing it in a variable named `sumLastColumn`. 5. Iterate over each element in the third row and check if it is even. If an element is even, increment a variable named `countEven`. 6. Finally, print the array, the sum of elements in the last column, and the count of even elements in the third row.

Here's an example code snippet in C++ that accomplishes this task:

```cpp #include #include #include

int main() { // Declare the array int array2[5][5];

// Seed the random number generator std::srand(std::time(0));

// Fill the array and calculate the sum of elements in the last column int sumLastColumn = 0; for (int i = 0; i < 5; i++) { for (int j = 0; j < 5; j++) { // Generate a random integer in the range from -10 to 10 array2[i][j] = std::rand() % 21 - 10;

// Calculate the sum of elements in the last column if (j == 4) { sumLastColumn += array2[i][j]; } } }

// Count the number of even elements in the third row int countEven = 0; for (int j = 0; j < 5; j++) { if (array2[2][j] % 2 == 0) { countEven++; } }

// Print the array std::cout << "Array2:" << std::endl; for (int i = 0; i < 5; i++) { for (int j = 0; j < 5; j++) { std::cout << array2[i][j] << " "; } std::cout << std::endl; }

// Print the sum of elements in the last column std::cout << "Sum of elements in the last column: " << sumLastColumn << std::endl;

// Print the count of even elements in the third row std::cout << "Count of even elements in the third row: " << countEven << std::endl;

return 0; } ```

Please note that the random number generator is seeded with the current time to ensure different random values each time the program is run. The `% 21 - 10` expression is used to generate random integers in the range from -10 to 10.

Task 4: Finding the Sum of Odd Elements in the Fourth Row of a 5x3 Array

To find the sum of odd elements in the fourth row of a 5x3 array consisting of integers in the range from -5 to 12, you can follow these steps:

1. Declare a 5x3 array named `array3` of type `int`. 2. Use nested loops to iterate over each element of the array. 3. Inside the loops, generate a random integer in the range from -5 to 12 and assign it to the current element. 4. After filling the array, iterate over each element in the fourth row and check if it is odd. 5. If an element is odd, add it to a variable named `sumOdd`. 6. Finally, print the array and the value of `sumOdd`.

Here's an example code snippet in C++ that accomplishes this task:

```cpp #include #include #include

int main() { // Declare the array int array3[5][3];

// Seed the random number generator std::srand(std::time(0));

// Fill the array and calculate the sum of odd elements in the fourth row int sumOdd = 0; for (int i = 0; i < 5; i++) { for (int j = 0; j < 3; j++) { // Generate a random integer in the range from -5 to 12 array3[i][j] = std::rand() % 18 - 5;

// Check if the element is odd if (array3[i][j] % 2 != 0 && i == 3) { sumOdd += array3[i][j]; } } }

// Print the array std::cout << "Array3:" << std::endl; for (int i = 0; i < 5; i++) { for (int j = 0; j < 3; j++) { std::cout << array3[i][j] << " "; } std::cout << std::endl; }

// Print the sum of odd elements in the fourth row std::cout << "Sum of odd elements in the fourth row: " << sumOdd << std::endl;

return 0; } ```

Please note that the random number generator is seeded with the current time to ensure different random values each time the program is run. The `% 18 - 5` expression is used to generate random integers in the range from -5 to 12.

0 0

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

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

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

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