面向对象:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace 计算类9._3
{
class Program
{
static void Main(string[] args)
{
int x1 = -1;
int y1 = -2;
int x2 = int.Parse(Console.ReadLine());
int y2 = int.Parse(Console.ReadLine());
double xdiff = (x2 - x1) * (x2 - x1);
double ydiff=(y2-y1)*(y2-y1);
double distance = Math.Sqrt(xdiff + ydiff);
Console.WriteLine(distance);
Console.WriteLine(distance);
Console.ReadKey();
}
}
}
面向过程:
//program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace 计算类9._3
{
class Program
{
static void Main(string[] args)
{
int x2 = int.Parse(Console.ReadLine());
int y2 = int.Parse(Console.ReadLine());
Point p1 = new Point();
Point p2 = new Point(x2,y2);
double distance= p1.Distance(p2);
Console.WriteLine(distance);
Console.ReadKey();
}
}
}
//Point.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace lainxi1
{
class Point
{
private int x;
private int y;
public Point()
{
x = -1;
y = -1;
}
public double Distance(Point p)
{
int xdiff = x - p.x;
int ydiff = y - p.y;
return Math.Sqrt(xdiff*xdiff+ydiff*ydiff);
}
}
}