Venciity

[ Telerik C#] Primitives And Variables - EX 3

Feb 13th, 2014
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.01 KB | None | 0 0
  1. // 3. Write a program that safely compares floating-point numbers with precision
  2. // of 0.000001. Examples: (5.3 ; 6.01) ---> false;  (5.00000001 ; 5.00000003) ---> true
  3.  
  4. using System;
  5.  
  6. namespace _03_SaveCompare
  7. {
  8.     class SaveCompare
  9.     {
  10.         static void Main()
  11.         {
  12.             // NOTE: This solution works only with numbers that have x <= 7 digits
  13.             Console.Write("Please enter the firs real number: ");
  14.             float number1 = float.Parse(Console.ReadLine());
  15.  
  16.             Console.Write("Please enter the second real number: ");
  17.             float number2 = float.Parse(Console.ReadLine());
  18.  
  19.             Console.WriteLine("The two numbers are {0} and {1}",number1,number2);
  20.  
  21.             if (number1 == number2)
  22.             {
  23.                 Console.WriteLine("The numbers are equal with precision of 0.000001");
  24.             }
  25.             else
  26.             {
  27.                 Console.WriteLine("The numbers aren`t equal with precision of 0.000001");
  28.             }
  29.         }
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment