Нужно переписать код на С# с Паскаль - C#
Формулировка задачи:
Вот код на Паскале.
var xx,yy:array[1..100] of real; a1,b1,c1,st,s_mn:real; i,n:integer; procedure line(x0,y0,x,y:real;var l:real); begin l:=sqrt(sqr(x-x0)+sqr(y-y0)); end; procedure pl(a,b,c:real; var s:real); var p:real; begin p:=(a+b+c)/2; s:=sqrt(p*(p-a)*(p-b)*(p-c)); end; begin readln(n); for i:=1 to n do readln(xx[i],yy[i]); s_mn:=0; for i:=1 to n-2 do begin line(xx[1],yy[1],xx[i+1],yy[i+1],a1); line(xx[i+1],yy[i+1],xx[i+2],yy[i+2],b1); line(xx[i+2],yy[i+2],xx[1],yy[1],c1); pl(a1,b1,c1,st); s_mn:=s_mn+st; end; writeln(s_mn); end. end.
Решение задачи: «Нужно переписать код на С# с Паскаль»
textual
Листинг программы
using System;
namespace ConsoleApplication1
{
class Program
{
static int N;
static double[] xx = new double[100], yy = new double[100];
static void Main(string[] args)
{
N = Convert.ToInt32(Console.ReadLine());
string[] pair;
for (int i = 0; i < N; i++)
{
pair = Console.ReadLine().Split(' ');
xx[i] = Convert.ToDouble(pair[0]);
yy[i] = Convert.ToDouble(pair[1]);
}
double s_mn = 0;
double a, b, c;
for (int i = 0; i < N - 1; i++)
{
a = Line(xx[0], yy[0], xx[i + 1], yy[i + 1]);
b = Line(xx[i + 1], yy[i + 1], xx[i + 2], yy[i + 2]);
c = Line(xx[i + 2], yy[i + 2], xx[0], yy[0]);
s_mn += Pl(a, b, c);
}
Console.WriteLine(s_mn);
Console.ReadKey();
}
static double Line(double x0, double y0, double x, double y)
{
return Math.Sqrt(Math.Pow(x - x0, 2) + Math.Pow(y - y0, 2));
}
static double Pl(double a, double b, double c)
{
double p = (a + b + c) / 2;
return Math.Sqrt(p * (p - a) * (p - b) * (p - c));
}
}
}