Информатика, вопрос задал Clexxer1997 , 7 лет назад

1. Дана матрица А, состоящая из N строк и М столбцов. Найти наименьший среди отрицательных и наибольший среди положительных элементов. Предусмотреть случай отсутствия положительных или отрицательных элементов в матрице.

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

Ответил MA3EIN
1

#include <iostream>

#include <time.h>

#include <stdlib.h>

#include <iomanip>

using namespace std;

int main() {

srand(time(0));

int n,z;

cin >> n >> z;

int array[n][z];

for(int i = 0;i<n;i++)

{

cout << endl;

for(int j = 0;j<z;j++)

{

array[i][j] = rand()%100-50;

cout << array[i][j] << setw(5);

}

cout << endl << endl;

}

cout << endl;

int index1,index2;

int Index1,Index2;

int min = array[0][0];

int max = array[0][0];

for(int i = 0;i<n;i++)

{

for(int j = 0;j<z;j++)

{

if(array[i][j]>=0)

{

if(array[i][j]>max)

{

max=array[i][j];

index1=i;

index2=j;

}

}

if(array[i][j]<0)

{

if(array[i][j]<min)

{

min=array[i][j];

Index1=i;

Index2=j;

}

}

}

}

cout << "max=" << max << endl;

cout << "Index po I" << index1 << endl;

cout << "Index po J" << index2 << endl;

cout << "min=" << min << endl;

cout << "Index po I" << Index1 << endl;

cout << "Index po J" << Index2 << endl;

}

Новые вопросы