fork download
  1. using System;
  2.  
  3. public class Program
  4. {
  5. public static void Main()
  6. {
  7. int h = 14; // часы
  8. int m = 30; // минуты
  9. int s = 45; // секунды
  10.  
  11. h = h % 12;
  12.  
  13. int totalSeconds = h * 3600 + m * 60 + s;
  14.  
  15. double angle = (totalSeconds * 360.0) / 43200.0;
  16.  
  17. angle = angle % 360;
  18.  
  19. Console.WriteLine($"Время: {(h == 0 ? 12 : h)}:{m:00}:{s:00}");
  20. Console.WriteLine($"Угол часовой стрелки: {angle:F2}°");
  21.  
  22. Console.WriteLine("\nДополнительные примеры:");
  23. Console.WriteLine("======================");
  24.  
  25. TestTime(0, 0, 0);
  26. TestTime(3, 0, 0);
  27. TestTime(6, 0, 0);
  28. TestTime(9, 0, 0);
  29. TestTime(12, 0, 0);
  30. TestTime(15, 30, 0);
  31. }
  32.  
  33. public static void TestTime(int h, int m, int s)
  34. {
  35. int hour12 = h % 12;
  36. int totalSeconds = hour12 * 3600 + m * 60 + s;
  37. double angle = (totalSeconds * 360.0) / 43200.0;
  38. angle = angle % 360;
  39.  
  40. Console.WriteLine($"{(h == 0 || h == 12 ? 12 : h % 12)}:{m:00}:{s:00} -> {angle:F2}°");
  41. }
  42. }
  43.  
Success #stdin #stdout 0.08s 31232KB
stdin
Standard input is empty
stdout
Время: 2:30:45
Угол часовой стрелки: 75.38°

Дополнительные примеры:
======================
12:00:00 -> 0.00°
3:00:00 -> 90.00°
6:00:00 -> 180.00°
9:00:00 -> 270.00°
12:00:00 -> 0.00°
3:30:00 -> 105.00°