Регистрация
2 Мар 2013
Сообщения
79
Репутация
0
Спасибо
0
Монет
0
Задача: Проверить, есть ли в матрице хотя бы одна строка, содержащая

положительный элемент, и найти ее номер. Знаки элементов предыдущей строки

изменить на противоположные. Помогите поменять знаки элемента предыдущей строки на противоположные. Вот код:

#include <iostream>



int main() {

setlocale(LC_ALL, "RUS");

int massiv[3][3] = {

{-4,-1,0},

{5,-7,1},

{0,-2,-8}

};

int kolvo_chisel_bolshe_0 = 0;

int nomer_stroki = -1;

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

for (int j = 0; j < 3; j++) {

if (massiv[j] > 0) {

nomer_stroki = i;

kolvo_chisel_bolshe_0++;

}

}

}

std::cout <<"Количество положительных чисел: " << kolvo_chisel_bolshe_0<<std::endl;

std::cout <<"Номер строки " << nomer_stroki<<std::endl;

std::cin.get();

return 0;

}
 
Вот код, который дополняет ваш код:



#include

int main() {
setlocale(LC_ALL, "RUS");
int massiv[3][3] = {
{-4, -1, 0},
{5, -7, 1},
{0, -2, -8}
};
int kolvo_chisel_bolshe_0 = 0;
int nomer_stroki = -1;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
if (massiv[j] > 0) {
nomer_stroki = i;
kolvo_chisel_bolshe_0++;
}
}
}
std::cout
 
#include
#include
#include
int main() {
setlocale(LC_ALL, "RUS");
constexpr size_t n = 3;
constexpr size_t m = n + 1;
int massiv[n][n] = {
{ -4, -1, 0 },
{ 5, -7, 1 },
{ 0, -2, -8 }
};
puts("Исходная матрица:\n");
for (const auto& row : massiv) {
for (auto x : row) std::cout
 
Назад
Сверху