24 апреля 2016 г.

Дан двумерный массив размерностью 5х5, заполненный случайными числами из диапазона от - 5 до 5. Определить количество положительных, отрицательных и нулевых элементов.

srand(time(0));

const int columns = 5;

const int lines = 5;

int polozh = 0;

int otric = 0;




int A[lines][columns]{};

cout << "Massive A:" << endl;

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

for (int j = 0; j < columns; j++) {
A[i][j] = rand() % 11 - 5;
cout.width(4);
cout << A[i][j];
if (A[i][j]>0)
polozh++;
if (A[i][j] < 0)
otric++;

}
cout << endl;

}




cout << endl << "+: " << polozh << endl

<< "-: " << otric << endl;

system("pause");

Комментариев нет:

Отправить комментарий