Algorithm Analysis
A number n is integer if its whole part is equal to itself. That is, the following equality holds: .
Algorithm Implementation
Read a real number n.
scanf("%lf", &n);
Compare the number n with its whole part. If these values are equal, then the number n 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 n = float(input()) if math.floor(n) == n: print("Ok") else: print("No")