【演算法Ⅰ~Ⅳ(C++實現)】習題3.1 尋找int float double能表示的最大最小值

來源:互聯網
上載者:User

包含標頭檔limits.h

numeric_limits<類型>::max()   求某資料類型的最大值(min()則求最小值)

浮點數的最小值是能表示的最小正數

cout.setf( ios::showbase|ios::uppercase );        cout << "int min = " << numeric_limits<int>::min() << "---" << hex << numeric_limits<int>::min() << endl;        cout.unsetf( ios::hex );        cout << "int max = " << numeric_limits<int>::max() << "---" << hex << numeric_limits<int>::max() << endl;        cout << endl;        cout.unsetf( ios::hex );        cout << "lont int min = " << numeric_limits< long int>::min() << "---" << hex << numeric_limits<long int>::min() << endl;        cout.unsetf( ios::hex );        cout << "long int max = " << numeric_limits<long int>::max() << "---" << hex << numeric_limits<long int>::max() << endl;        cout << endl;        cout.unsetf( ios::hex );        cout << "short int min = " << numeric_limits<short int>::min() << "---" << hex                 << numeric_limits<short int>::min() << endl;        cout.unsetf( ios::hex );        cout << "short int max = " << numeric_limits<short int>::max() << "---" << hex                 << numeric_limits<short int>::max() << endl;        cout << endl;        cout.unsetf( ios::hex );        cout << "float min = " << numeric_limits<float>::min() << "---" << hex << numeric_limits<float>::min() << endl;        cout << "float max = " << numeric_limits<float>::max() << "---" << hex << numeric_limits<float>::max() << endl;        cout << endl;        cout << "double min = " << numeric_limits<double>::min() << "---" << hex << numeric_limits<double>::min() << endl;        cout << "double max = " << numeric_limits<double>::max() << "---" << hex << numeric_limits<double>::max() << endl;        cout << endl;

結果:

int min = -2147483648---0X80000000int max = 2147483647---0X7FFFFFFFlont int min = -2147483648---0X80000000long int max = 2147483647---0X7FFFFFFFshort int min = -32768---0X8000short int max = 32767---0X7FFFfloat min = 1.17549E-38---1.17549E-38float max = 3.40282E+38---3.40282E+38double min = 2.22507E-308---2.22507E-308double max = 1.79769E+308---1.79769E+308

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.