I am trying to implement user defined function which tests if a number is an integer:
#include <iostream>
#include <typeinfo>
using namespace std;
bool integer(float k){
if (k==20000) return false;;
if (k==(-20000)) return false;
if (k==0) return true;
if (k<0) return integer(k+1);
else if(k>0) return integer (k-1);
return false;
}
int main(){
float s=23.34;
float s1=45;
cout<<boolalpha;
cout<<integer(s)<<endl;
cout<<integer(s1)<<endl;
return 0;
}
So the idea is that,if a number is an integer, does not matter if it is a negative or positive , if we decrease or increase it by one, we must get zero, but the problem is, that how can we create upper and lower bounds for increasing and decreasing?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…