Advertisement
ElliasBLR

Пифагор и гипотенуза

Mar 4th, 2021
1,536
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.28 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ConsoleApplication1
  4. {
  5.  
  6.     class Program
  7.     {
  8.         //Найдите периметр N-угольника, заданного координатами вершин на плоскости {(Xi; Yi)}, (i = 1, … < N).
  9.         static double P_Calculation(double[] x,double[] y,int n)
  10.         {
  11.             double P = 0;
  12.             for (int i =0; i<n;i++)
  13.             {
  14.                 int j = (i + 1) % n;
  15.                 P = P + Math.Sqrt(Math.Pow(x[i] - x[j], 2) + Math.Pow(y[i] - y[j], 2));
  16.  
  17.             }
  18.  
  19.             return P;
  20.         }
  21.         static void Main(string[] args)
  22.         {
  23.             int n = 6;
  24.             Console.WriteLine("Координаты вершин x и y соотвественно");
  25.             double[] x = new double[]{ 2.0, 3.0, 6.0, 6.0, 4.0, 5.0 };
  26.             foreach(double i in x)
  27.             {
  28.                 Console.Write(i + " ");
  29.             }
  30.             Console.WriteLine();
  31.             double[] y = new double[]{ 3.0, 6.0, 5.0, 2.0, 1.0, 7.0 };
  32.             foreach (double i in y)
  33.             {
  34.                 Console.Write(i + " ");
  35.             }
  36.             Console.WriteLine();
  37.             Console.WriteLine("P= " + P_Calculation(x, y,n));
  38.  
  39.             Console.ReadKey();
  40.  
  41.         }
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement