Advertisement
dimipan80

Possible Triangles

May 18th, 2015
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.91 KB | None | 0 0
  1. /* In Geometry a triangle is real if the sum of the shortest two sides is larger than the longest side. Write a program that checks three real numbers if there is a possible triangle to be built from them. You are given lines of three real numbers. The last line will hold “End”. Print all the possibilities in the format “a+b>c”. Where a and b are the shortest sides and c is the longest.
  2.  * The first lines hold the three real numbers, separated by single space. The last line holds the word “End”. The input lines will be distinct (no duplicates are allowed).
  3.  * Print at the console all possible triangles found in the input sequence in format "a+b>c" (without any spaces), each at a separate line. The order of the output lines should be the same as the order they appear in the input. The numbers should be printed with 2 digits after the decimal sign. Print "No" in case no triangle is possible among the input sequence of numbers. */
  4.  
  5. namespace Possible_Triangles
  6. {
  7.     using System;
  8.     using System.Linq;
  9.  
  10.     class PossibleTriangles
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             bool isFoundTriangle = false;
  15.  
  16.             string inputLine = Console.ReadLine();
  17.             while (inputLine != "End")
  18.             {
  19.                 double[] sides = inputLine.Split(' ').Select(double.Parse).ToArray();
  20.                 if (sides.Length == 3)
  21.                 {
  22.                     Array.Sort(sides);
  23.                     if (sides[0] + sides[1] > sides[2])
  24.                     {
  25.                         isFoundTriangle = true;
  26.                         Console.WriteLine("{0:F2}+{1:F2}>{2:F2}",
  27.                             sides[0], sides[1], sides[2]);
  28.                     }
  29.                 }
  30.  
  31.                 inputLine = Console.ReadLine();
  32.             }
  33.  
  34.             if (!isFoundTriangle)
  35.             {
  36.                 Console.WriteLine("No");
  37.             }
  38.         }
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement