Вопрос задан 21.08.2018 в 21:16. Предмет Информатика. Спрашивает Яшкова Нина.

Массив А(N,M).В каждом столбце найти среднее арифметическое нечетных элементов.Из полученных

значений сформировать одномерный массив.
0 0
Перейти к ответам

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

Внимание! Ответы на вопросы дают живые люди. Они могут содержать ошибочную информацию, заблуждения, а также ответы могут быть сгенерированы нейросетями. Будьте внимательны. Если вы уверены, что ответ неверный, нажмите кнопку "Пожаловаться" под ответом.
Отвечает Рублева Александра.
Uses Crt;
const
n=5;m=7;
var
a:array[1..n,1..m]of integer;
b:array[1..m]of real;
i,j,k,c:integer;
s:real;
begin
clrScr;
    for i:=1 to n do
        begin
            writeln;
               for j:=1 to m do
                  begin
                     a[i,j]:=random(30);
                      write(a[i,j]:4);
                  end;
          end;
writeln;
for j:=1 to m do
  begin
      s:=0;k:=0;
          for i:=1 to n do
               if a[i,j]mod 2<>0 then
                   begin
                       s:=s+a[i,j];
                        k:=k+1;
                   end;
      if k<>0 then
         begin
            c:=c+1;
            b[c]:=s/k;
         end;
     end;
for i:=1 to c do
   write(b[i]:8:2);
readkey;
end.

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

Task: Array Operations

To solve this problem, we need to perform the following steps: 1. Find the arithmetic mean of the odd elements in each column of the array A(N, M). 2. Form an one-dimensional array from the obtained mean values.

Let's proceed with the implementation.

Step 1: Finding Arithmetic Mean of Odd Elements in Each Column

To find the arithmetic mean of the odd elements in each column of the array A(N, M), we can use the following algorithm: - Iterate through each column of the array. - For each column, calculate the arithmetic mean of the odd elements.

Step 2: Forming a One-Dimensional Array

After obtaining the mean values, we can form a one-dimensional array from these values.

Implementation in JavaScript

Here's a sample JavaScript code to achieve this:

```js // Sample array A(N, M) var A = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ];

// Function to calculate arithmetic mean of odd elements in a column function calculateMean(column) { var oddElements = column.filter(num => num % 2 !== 0); var sum = oddElements.reduce((acc, val) => acc + val, 0); return sum / oddElements.length; }

// Calculate mean values for each column var meanValues = []; for (var j = 0; j < A[0].length; j++) { var column = A.map(row => row[j]); meanValues.push(calculateMean(column)); }

// Forming the one-dimensional array var oneDimensionalArray = meanValues; console.log(oneDimensionalArray); ```

This code first calculates the arithmetic mean of the odd elements in each column of the array A(N, M) and then forms a one-dimensional array from the obtained mean values.

Feel free to modify the array A and test the code with different input arrays.

Let me know if you need further assistance!

0 0

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

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

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