Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* 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.
- * 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).
- * 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. */
- namespace Possible_Triangles
- {
- using System;
- using System.Linq;
- class PossibleTriangles
- {
- static void Main(string[] args)
- {
- bool isFoundTriangle = false;
- string inputLine = Console.ReadLine();
- while (inputLine != "End")
- {
- double[] sides = inputLine.Split(' ').Select(double.Parse).ToArray();
- if (sides.Length == 3)
- {
- Array.Sort(sides);
- if (sides[0] + sides[1] > sides[2])
- {
- isFoundTriangle = true;
- Console.WriteLine("{0:F2}+{1:F2}>{2:F2}",
- sides[0], sides[1], sides[2]);
- }
- }
- inputLine = Console.ReadLine();
- }
- if (!isFoundTriangle)
- {
- Console.WriteLine("No");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement