min/max

Sep 18, 2014 at 1:28pm
I have a 2d Array (static matrix) and I'd like to calculate and subtract the row minimum from each row.
I've trouble in calculate even the minimum.
Could you give me some help please?

I've tried a very simple code in Visual Studio 2006 but it said that the identifier "fmin"is not found

1
2
3
4
5
6
7
8
9
10
11
#include"stdafx.h"
#include<stdio.h>
#include<math.h>

int main(){
float a=100.0;
float b= 10;
float res;
res= fmin(a,b);
printf("result =%f", res);
}


thank you very much!
Sep 18, 2014 at 1:39pm
Why VS2006? There are free current compilers.

Look at http://www.cplusplus.com/reference/algorithm/min_element/
Even though your current compiler would not have that function, you should notice that the algorithm uses a loop to look at each element in range.
Last edited on Sep 18, 2014 at 1:40pm
Sep 18, 2014 at 2:40pm
You mean VS6, right? There isn't a VS2006, it's the version before VS2003 and VS2002.

You should use std::min. Be careful, Microsoft have a macros max/min somewhere, and they clash with the stl versions. You can switch them off by defining NO_MINMAX or something like that ... I can't remember
1
2
3
4
5
6
7
8
9
10
11
.
#include <algorithm>
#include <stdio.h>
int main()
{
    float a=100.0;
    float b= 10;
    float res = std::min(a, b);

    printf("result =%f", res);
}
Last edited on Sep 18, 2014 at 2:41pm
Topic archived. No new replies allowed.