C++ 判断一个数是否在int的取值范围内

xiaoxiao2021-02-28  92

#include <iostream> #include<climits> #include<cstdio> using namespace std; bool is_int(long long); int main() { long long theOne; cout << "EOF means ending"<<endl; cout << "Please input the test number:"<<endl; cin >> theOne; while(theOne!=EOF) { if(is_int(theOne)) cout << "YES"<<endl; else cout << "Out of range"<<endl; cin.clear(); cin >>theOne; } return 0; } bool is_int(long long x) { if(x>=INT_MIN&&x<=INT_MAX) return true; else return false; }
转载请注明原文地址: https://www.6miu.com/read-53372.html

最新回复(0)