Calculate Distance Between 2 Points

Language

This code allows you to calculate distance between two points. Download the zip file or copy/paste the code below.
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApplication3
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. Console.WriteLine("Please Enter x1 and y1 coordinates:");
  14. double x1 = Convert.ToDouble(Console.ReadLine());
  15. double y1 = Convert.ToDouble(Console.ReadLine());
  16.  
  17. Console.WriteLine("Please enter x2 and y2 coordinates:");
  18. double x2 = Convert.ToDouble(Console.ReadLine());
  19. double y2 = Convert.ToDouble(Console.ReadLine());
  20.  
  21. double result = Distance(x1, x2, y1, y2);
  22. Console.WriteLine("Distance between coordinates {0},{1} and{2},{3} is{4:F}", x1, y1, x2 , y2, result);
  23.  
  24. Console.ReadKey();
  25. }
  26.  
  27. private static double Distance(double x1, double x2, double y1, double y2)
  28. {
  29. double temp1 = Math.Pow((x2 - x1),2);
  30. double temp2 = Math.Pow((y2 - y1),2);
  31. double answer = Math.Sqrt(temp1 + temp2);
  32. return answer;
  33. }
  34. }
  35. }

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.

FOR YOUR OWN SAFETY, PLEASE:

1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

Comments

Submitted byJos enockon Mon, 08/26/2019 - 20:49

COMMENT About the new calculator app, it seems to be good

Add new comment