Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2017
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _09.Triangle_Formations
  8. {
  9. //You are given 3 integer numbers: a, b and c, which will represent the 3 sides of a triangle. Your task is to check whether the triangle is valid.
  10. // If it is, print "Triangle is valid.".
  11. //Otherwise print "Invalid Triangle." and end the program.
  12. //If it is valid, you have to check if it is a right triangle (a2 + b2 == c2).
  13. //If it is a right triangle, print "Triangle has a right angle between sides a and b", depending on which side forms a right angle.
  14. //If the sides b and c form a right angle, print "Triangle has a right angle between sides b and c", and so on.
  15.  
  16. class Triangle
  17. {
  18. static void Main(string[] args)
  19. {
  20. int a = int.Parse(Console.ReadLine());
  21. int b = int.Parse(Console.ReadLine());
  22. int c = int.Parse(Console.ReadLine());
  23.  
  24. if ((a * a) + (b * b) == (c * c) || (a * a) + (c * c) == (b * b) || (b * b) + (c * c) == (a * a) || (a == b && b == c))
  25. {
  26. Console.WriteLine("Triangle is valid.");
  27. if ((a * a) + (b * b) == (c * c)) Console.WriteLine("Triangle has a right angle between sides a and b");
  28. if ((a * a) + (c * c) == (b * b)) Console.WriteLine("Triangle has a right angle between sides a and c");
  29. if ((b * b) + (c * c) == (a * a)) Console.WriteLine("Triangle has a right angle between sides b and c");
  30. if (a == b && b == c) Console.WriteLine("Triangle has no right angles");
  31.  
  32. }
  33. else
  34. {
  35. Console.WriteLine("Invalid Triangle.");
  36. }
  37.  
  38. }
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement