Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace ConsoleApplication1
- {
- class Program
- {
- //Найдите периметр N-угольника, заданного координатами вершин на плоскости {(Xi; Yi)}, (i = 1, … < N).
- static double P_Calculation(double[] x,double[] y,int n)
- {
- double P = 0;
- for (int i =0; i<n;i++)
- {
- int j = (i + 1) % n;
- P = P + Math.Sqrt(Math.Pow(x[i] - x[j], 2) + Math.Pow(y[i] - y[j], 2));
- }
- return P;
- }
- static void Main(string[] args)
- {
- int n = 6;
- Console.WriteLine("Координаты вершин x и y соотвественно");
- double[] x = new double[]{ 2.0, 3.0, 6.0, 6.0, 4.0, 5.0 };
- foreach(double i in x)
- {
- Console.Write(i + " ");
- }
- Console.WriteLine();
- double[] y = new double[]{ 3.0, 6.0, 5.0, 2.0, 1.0, 7.0 };
- foreach (double i in y)
- {
- Console.Write(i + " ");
- }
- Console.WriteLine();
- Console.WriteLine("P= " + P_Calculation(x, y,n));
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement