double maxElemUnderD(double matric, int size)
{
double elem = 0;
for (int i = 1; i < size; i++)
{
for (int j = i; j < size; j++)
{
if (matric[i][j] > elem)
{
elem = matric[i][j];
}
}
}
return elem;
}
void main()
{
setlocale(LC_ALL, "rus");
double eps = 0.01;
const int size = 3;
double maxElem;
double matric[size][size] =
{
2, -1, 3,
-1, 4, 2,
3, 2, 5
};
maxElem = maxElemUnderD(matric, size);
}
#include "iostream"
const int size = 3;
double maxElemUnderD(double &matric[size][size])
{
double elem = 0;
for (int i = 1; i < size; i++)
{
for (int j = i; j < size; j++)
{
if (matric[i][j] > elem)
{
elem = matric[i][j];
}
}
}
return elem;
}
int main()
{
double eps = 0.01;
double maxElem;
double matric[size][size] =
{
{2, -1, 3},
{-1, 4, 2},
{3, 2, 5}
};
maxElem = maxElemUnderD(matric);
std::cout << maxElem << std::endl;
return 0;
}
Как передать двумерный массив в возвращаемую функцию?
#include<iostream>
#include<limits>
#include<algorithm>
const int size = 3;
auto maxElemUnderD()
{
return [](double(&mtx)[size][size]){
double maxelm = std::numeric_limits<double>::min();
for(auto const& row : mtx)
{
double max = *std::max_element(std::cbegin(row), std::cend(row));
if(max > maxelm) maxelm = max;
}
return maxelm;
};
}
int main()
{
double matric[size][size] =
{
{2, -1, 3},
{-1, 4, 2},
{3, 2, 5}
};
double maxElem = maxElemUnderD()(matric);
std::cout << maxElem << std::endl;
}