
В квадратной матрице найти сумму нечётных элементов


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

uses crt;
Var mas:array[1..1000, 1..1000] of integer;
N,i,j,sum:integer;
Begin
Writeln('Введите размер матрицы N*N');
Write('N = ');readln(N);
if (N>1000) or (N<1) then
Writeln('Ошибка, указанные значения выходят за пределы матрицы') else
Begin
Writeln('Введите элементы матрицы');
sum:=0;
for i:=1 to N do
for j:=1 to N do
Begin
readln(mas[i,j]);
if (mas[i,j] mod 2 <> 0)
then sum:=sum+mas[i,j];
end;
Writeln();
Writeln('Исходная матрица');
for i:=1 to N do
Begin
for j:=1 to N do
Begin
Write(mas[i,j], ' ');
end;
Writeln();
end;
Writeln();
Writeln('Сумма нечетных элементов = ',sum);
end;
readln;
end.



Finding the Sum of Odd Elements in a Square Matrix
To find the sum of odd elements in a square matrix, you can iterate through each element of the matrix and check if it's an odd number. If it is, add it to the running sum. Here's a step-by-step guide on how to achieve this:
1. Iterate Through the Matrix: - Start by iterating through each element of the square matrix.
2. Check for Odd Numbers: - For each element, check if it's an odd number.
3. Calculate the Sum: - If the element is odd, add it to the running sum.
4. Return the Sum: - Once all elements have been checked, the running sum will represent the sum of all odd elements in the matrix.
Let's apply this process to the given square matrix:
``` |30||55||95||105| |40||80||100||120| |15||20||70||85| |20||35||80||95| ```
Calculating the Sum of Odd Elements
Based on the provided square matrix, the sum of the odd elements can be calculated as follows:
- Odd elements in the matrix: 55, 95, 15, 85, 35, 95 - Sum of the odd elements: 55 + 95 + 15 + 85 + 35 + 95 = 380
Therefore, the sum of the odd elements in the given square matrix is 380.


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