Answer the question
In order to leave comments, you need to log in
How to pass a 2D array to a returned function?
How to pass an array to a function and return a value?
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);
}
Answer the question
In order to leave comments, you need to log in
I offer you an excellent and simple library for creating both static and dynamic charts: Chartist.js
#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;
}
How to pass a two-dimensional array to the returned function ?
#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;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question