[Solved] Nearest Integer less than the given value [duplicate]


As told in the comments, you can see how to check if a number is an integer or not, and perform an appropriate action: Checking if float is an integer.

However, if you want more interesting way, without any conditions:

float a;
float result;
cin >> a;
result = std::floor(a) - !std::ceil(a - std::floor(a)); // ceil(a - 1) <--- As told in @Naman comment, it's a better way.
cout << result << endl;

2

solved Nearest Integer less than the given value [duplicate]