Advertisement
Guest User

Untitled

a guest
Jul 12th, 2014
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.36 KB | None | 0 0
  1. using System;
  2.  
  3. class Triangle
  4. {
  5.     static void Main()
  6.     {
  7.         int aX = int.Parse(Console.ReadLine());
  8.         int aY = int.Parse(Console.ReadLine());
  9.         int bX = int.Parse(Console.ReadLine());
  10.         int bY = int.Parse(Console.ReadLine());
  11.         int cX = int.Parse(Console.ReadLine());
  12.         int cY = int.Parse(Console.ReadLine());
  13.  
  14.         decimal lineA = calculateLine(bX, aX, bY, aY);
  15.         decimal lineB = calculateLine(cX, bX, cY, bY);
  16.         decimal lineC = calculateLine(cX, aX, cY, aY);
  17.  
  18.         if (isTriangle(lineA,lineB,lineC))
  19.         {
  20.             Console.WriteLine("Yes");
  21.            
  22.             decimal p = (lineA + lineB + lineC) / 2;
  23.             decimal area = (decimal)Math.Sqrt((double)p * (double)(p - lineA) * (double)(p - lineB) * (double)(p - lineC));
  24.             Console.WriteLine("{0:f2}",area);
  25.         }
  26.         else
  27.         {
  28.             Console.WriteLine("No");
  29.             Console.WriteLine("{0:f2}",calculateLine(aX,bX,aY,bY));
  30.         }
  31.     }
  32.  
  33.     static decimal calculateLine(int x2, int x1, int y2, int y1)
  34.     {
  35.         decimal line = (decimal)Math.Sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
  36.         return line;
  37.     }
  38.  
  39.     static bool isTriangle(decimal a, decimal b, decimal c)
  40.     {
  41.         bool isTriangle = a + b > c && b + c > a && a + c > b;
  42.         return isTriangle;
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement