Advertisement
youuw

program z pierwszych zajęć programowania obiektowego

Oct 5th, 2023
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. static void Main(string[] args)
  2. {
  3. Console.Write("Wprowadź boki trójkąta oddzielając je spacją: ");
  4. string[] input = (Console.ReadLine() ?? "").Split(" ");
  5. if (input.Length != 3)
  6. {
  7. Console.ForegroundColor = ConsoleColor.Red;
  8. Console.WriteLine("Niepoprawna liczba boków");
  9. Console.ResetColor();
  10. return;
  11. }
  12. double[] edges = new double[3];
  13. for(int i = 0; i < input.Length; i++)
  14. {
  15. if(!double.TryParse(input[i], out edges[i]))
  16. {
  17. Console.ForegroundColor = ConsoleColor.Red;
  18. Console.WriteLine("Niepoprawnie wprowadzone wartości długości boków");
  19. Console.ResetColor();
  20. return;
  21. }
  22. }
  23. if (edges[0] + edges[1] <= edges[2] || edges[0] + edges[2] <= edges[1] || edges[1] + edges[2] <= edges[0])
  24. {
  25. Console.ForegroundColor = ConsoleColor.Red;
  26. Console.WriteLine("Z podanych boków nie da się zbudować trójkąta");
  27. Console.ResetColor();
  28. return;
  29. }
  30.  
  31. double p = edges.Sum() / 2;
  32. double area = Math.Sqrt(p * (p - edges[0]) * (p - edges[1]) * (p - edges[2]));
  33. Console.WriteLine($"Pole trójkąta wynosi: {area}");
  34.  
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement