-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKod9_struct+inParam.cs
More file actions
54 lines (46 loc) · 1.44 KB
/
Kod9_struct+inParam.cs
File metadata and controls
54 lines (46 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using System.Diagnostics;
using System.Reflection.Metadata.Ecma335;
using System.Reflection.PortableExecutable;
/*Задача 9: in + структура
Создай struct Point3D { public double X,Y,Z; }
Напиши метод double GetDistance(in Point3D p1, in Point3D p2)
(расстояние между двумя точками в 3D: sqrt((x2-x1)^2 + (y2-y1)^2 + (z2-z1)^2))*/
namespace testing
{
public struct Point3D
{
public double X;
public double Y;
public double Z;
public Point3D(double x, double y, double z)
{
X = x;
Y = y;
Z = z;
}
public override string ToString()
{
return $"({X}, {Y}, {Z})";
}
}
internal class Program
{
static double GetDistance(in Point3D p1, in Point3D p2)
{
double dx = p2.X - p1.X;
double dy = p2.Y - p1.Y;
double dz = p2.Z - p1.Z;
double distance = Math.Sqrt((dx * dx) + (dy * dy) + (dz * dz));
return distance;
}
static void Main(string[] args)
{
Point3D a = new Point3D(1, 2, 3);
Point3D b = new Point3D(4, 5, 6);
double dist = GetDistance(in a, in b);
Console.WriteLine($"Точка A: {a}");
Console.WriteLine($"Точка B: {b}");
Console.WriteLine($"Расстояние: {dist:F2}");
}
}
}