Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 3. Write a program that safely compares floating-point numbers with precision
- // of 0.000001. Examples:(5.3 ; 6.01) ---> false; (5.00000001 ; 5.00000003) ---> true
- using System;
- namespace _03_SaveCompare
- {
- class SaveCompare
- {
- static void Main()
- {
- // NOTE: This solution works only with numbers that have x <= 7 digits
- Console.Write("Please enter the firs real number: ");
- float number1 = float.Parse(Console.ReadLine());
- Console.Write("Please enter the second real number: ");
- float number2 = float.Parse(Console.ReadLine());
- Console.WriteLine("The two numbers are {0} and {1}",number1,number2);
- if (number1 == number2)
- {
- Console.WriteLine("The numbers are equal with precision of 0.000001");
- }
- else
- {
- Console.WriteLine("The numbers aren`t equal with precision of 0.000001");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment