【算法Ⅰ~Ⅳ(C++实现)】习题3.1 寻找int float double能表示的最大最小值

包含头文件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---0X80000000
int max = 2147483647---0X7FFFFFFF

lont int min = -2147483648---0X80000000
long int max = 2147483647---0X7FFFFFFF

short int min = -32768---0X8000
short int max = 32767---0X7FFF

float min = 1.17549E-38---1.17549E-38
float max = 3.40282E+38---3.40282E+38

double min = 2.22507E-308---2.22507E-308
double max = 1.79769E+308---1.79769E+308


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值