maximum value and the minimum value of csv file
-
i have a csv file i been able to read it with qt but I would like to take the maximum value and the minimum value and put them in a variable
how can i do it please@genli This is a very simple programming exercise. What did you try so far? You simply need to iterate over the values and in each iteration check whether the value is smaller than current smallest value or bigger than current biggest value.
-
@genli This is a very simple programming exercise. What did you try so far? You simply need to iterate over the values and in each iteration check whether the value is smaller than current smallest value or bigger than current biggest value.
-
Imin = listefinale[0];
Imax = listefinale[0];
for (int i=1; i<listefinale.size(); i++)
{
if (listefinale[i] < Imin)
Imin = listefinale[i];
if (listefinale[i] > Imax)
Imax = listefinale[i];
}
but it did work@genli it should are you sure you know the content of your listefinale?
anyway, since we're actually a c++ language:
QVector<int> listefinale( 100000,0 ); // create random numbers std::generate( listefinale.begin(), listefinale.end(), rand ); int Imin = *std::min_element(listefinale.begin(), listefinale.end()); int Imax = *std::max_element(listefinale.begin(), listefinale.end()); qDebug() << Imin << Imax;
-
@genli it should are you sure you know the content of your listefinale?
anyway, since we're actually a c++ language:
QVector<int> listefinale( 100000,0 ); // create random numbers std::generate( listefinale.begin(), listefinale.end(), rand ); int Imin = *std::min_element(listefinale.begin(), listefinale.end()); int Imax = *std::max_element(listefinale.begin(), listefinale.end()); qDebug() << Imin << Imax;