Что не так? - Я никак не могу сложить значения элементов в матрице - он выдает какие-то числа непонятные
Вот код:
#include
#include
#include
#include
#include
using namespace std;
int main()
{
setlocale (LC_ALL , "Russian");
int p(0);
int m[5][5];
srand (time(NULL));
for (int i(0); i < 5; i++)
{
cout << i + 1 << " строка: ";
for (int j(0); j < 5; j++)
{
m[j] = 1 + rand () % 10 - 1;
cout << m[j] << " | ";
p++;
}
cout << " ___________________________________ ";
}
for (int i(0); i < 5; i++)
{
cout << "Сумма элементов " << i + 1 << " строки: ";
for (int j(0); j < 5; j++)
{
p += m[j];
cout << p;
}
p = 0;
cout << endl;
}
_getch();
return 0;
}
Попробуйте программу
Вот код:
#include
#include
#include
#include
#include
using namespace std;
int main()
{
setlocale (LC_ALL , "Russian");
int p(0);
int m[5][5];
srand (time(NULL));
for (int i(0); i < 5; i++)
{
cout << i + 1 << " строка: ";
for (int j(0); j < 5; j++)
{
m[j] = 1 + rand () % 10 - 1;
cout << m[j] << " | ";
p++;
}
cout << " ___________________________________ ";
}
for (int i(0); i < 5; i++)
{
cout << "Сумма элементов " << i + 1 << " строки: ";
for (int j(0); j < 5; j++)
{
p += m[j];
cout << p;
}
p = 0;
cout << endl;
}
_getch();
return 0;
}
Попробуйте программу