Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- //Write a program that safely compares floating-point numbers with precision eps = 0.000001. Note that we cannot
- //directly compare two floating-point numbers a and b by a==b because of the nature of the floating-point arithmetic.
- //Therefore, we assume two numbers are equal if they are more closely to each other than a fixed constant eps. Examples:
- class ComparesFloat
- {
- static void Main()
- {
- Console.Write("First number: ");
- float firstNum = float.Parse(Console.ReadLine());
- Console.Write("second number: ");
- float secondNum = float.Parse(Console.ReadLine());
- bool isEqualNumbers = firstNum == secondNum;
- Console.Write("? Equal : ");
- Console.WriteLine(isEqualNumbers);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement