Integer#8876

Integer (Editorial)

The number is an integer if its integer part matches the number itself. That is, if the equality floor(n) = n holds.

Algorithm implementation

Read the real number .

scanf("%lf", &n);

Сompare the number with its integer part. If these values are equal, then is an integer.

if (floor(n) == n) puts("Ok");
else puts("No");

Java implementation

import java.util.*;

class Main 
{
  public static void main(String[] args) 
  {
    Scanner con = new Scanner(System.in);
    double n = con.nextDouble();

    if (Math.floor(n) == n) 
      System.out.println("Ok");
    else 
      System.out.println("No");

    con.close();
  }
}

Python implementation

import math

Read the real number .

n = float(input())

Сompare the number with its integer part. If these values are equal, then is an integer.

if math.floor(n) == n: print("Ok")
else: print("No")

Python implementation — is_integer

Read the real number .

n = float(input())

The method is\_integer() checks whether the given floating-point number represents an integer value (its fractional part is zero).

if n.is_integer(): print("Ok")
else: print("No")