Results 1 to 5 of 5

Thread: Use of the min() in C++

  1. #1
    Join Date
    Jan 2010
    Posts
    29

    Use of the min() in C++

    Hello, I am the student of the MSC. I have the knowledge of the C++ language. I can also have the knowledge of the functions of the C++ language. I want to know about the min() function of the C++ language. So, I would like to know how can I use the min() function in the C++ language. Can you have the information on the min() function of the C++ language.
    Last edited by Tailor; 13-02-2010 at 08:15 PM.

  2. #2
    Join Date
    May 2008
    Posts
    2,012

    Use of the min() in C++

    The following code of lines demonstrates you about the use of the min() function :
    Code:
    #include <iostream>
    #include <algorithm>
    using namespace std;
    int main () 
    {
      cout << "min(2,1)==" << min(2,1) << endl;
      cout << "min(1,2)==" << min(1,2) << endl;
      cout << "min(3.14,2.72)==" << min(3.14,2.72) << endl;
      cout << "min('a','z')==" << min('a','z') << endl;
      return 0;
    }
    Output:
    Code:
    min(2,1)==1
    min(1,2)==1
    min(3.14,2.72)==2.72
    min('a','z')==a

  3. #3
    Join Date
    Apr 2008
    Posts
    2,005

    Use of the min()

    Hello, According to my knowledge about the min() function that The min() function can be used for to find out the minimum character between the defined two values. The following can be the general syntax of the min() function :
    Code:
    template <class T> const T& min ( const T& a, const T& b );

  4. #4
    Join Date
    May 2008
    Posts
    2,297

    Use of the min()

    There can be the one more program on the min() function as follows :
    Code:
    #define NOMINMAX
    #include <iostream>
    #include <algorithm>
    using namespace std;
    int main()
    {
        cout << min(3, 5) << endl;
    }
    Output :
    Code:
    3

  5. #5
    Join Date
    Nov 2005
    Posts
    1,323

    The min()

    The min() function of the C++ language can returns the minimum value among the two values that means it can returns the lesser of p and q. The min() function of the C++ language can uses the < operator to check the minimum value. The behavior of min() function template can be equivalent to the following :
    Code:
    template <class S> const S& min ( const S& p, const S& q ) 
    {
      return (p<q)?p:q; 
    }

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,715,283,596.34202 seconds with 15 queries