C++ Program to Check if Given Number is Integer or Float

C++ Program to Check if Given Number is Integer or Float

Write C++ Program to Check if Given Number is Integer or Float

// CPP Program to check if given number is integer or float

#include <iostream>
#include <math.h>

using namespace std;

int main()
{
        float n;
        cout << "Enter the number :--> ";
        cin >> n;

        int x = floor(n); //typecasting float to int

        if ( x == n)
        {
                cout << "The entered number is an integer";
        }
        else
        {
                cout << "The entered number is float";
        }
        return 0;
}

Output:

Run 1:
Enter the number :--> 98.3
The entered number is float

Run 2:
Enter the number :--> 89
The entered number is an integer