Advertisement
Guest User

Untitled

a guest
Jan 30th, 2017
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.02 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace ConsoleApplication3
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int a = int.Parse(Console.ReadLine());
  14.             int b = int.Parse(Console.ReadLine());
  15.             int c = int.Parse(Console.ReadLine());
  16.             int[] array = { a, b, c };
  17.             array = array.OrderBy(number => number).ToArray();
  18.  
  19.             int sideA = array[0];
  20.             int sideB = array[1];
  21.             int sideC = array[2];
  22.  
  23.             int valid = 0;
  24.             bool rightAngle = Math.Pow(sideA, 2) + Math.Pow(sideB, 2) == Math.Pow(sideC, 2);
  25.             if ((a + b) > c)
  26.             {
  27.                 if ((b + c) > a)
  28.                 {
  29.                     if ((a + c) > b) //If a+b>c and a+c>b and b+c>a then it is valid  
  30.                     {
  31.                         valid = 1;
  32.                     }
  33.                 }
  34.             }
  35.  
  36.             if (valid == 1)
  37.             {
  38.                 Console.WriteLine("Triangle is valid.");
  39.                 if (rightAngle)
  40.                 {
  41.                     if (c > a && c > b)
  42.                     {
  43.                         Console.WriteLine("Triangle has a right angle between sides a and b");
  44.                     }
  45.                     else if (b > a && b > c)
  46.                     {
  47.                         Console.WriteLine("Triangle has a right angle between sides a and c");
  48.                     }
  49.                     else // a is the hypotenuse
  50.                     {
  51.                         Console.WriteLine("Triangle has a right angle between sides b and c");
  52.                     }
  53.                 }
  54.                 else
  55.                 {
  56.                     Console.WriteLine("Triangle has no right angles");
  57.                 }
  58.             }
  59.             else
  60.             {
  61.                 Console.WriteLine("Invalid Triangle.");
  62.             }
  63.         }
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement