Write a program to find angle of watch hand.
Anonymous
using System; class Program { static void Main(string[] args) { // Input: Hours and Minutes Console.Write("Enter the hours (1-12): "); int hours = int.Parse(Console.ReadLine()); Console.Write("Enter the minutes (0-59): "); int minutes = int.Parse(Console.ReadLine()); // Calculate the angle of the hour and minute hands double hourAngle = (hours % 12) * 30 + (minutes * 0.5); // 360 degrees / 12 hours = 30 degrees per hour, hour hand moves 0.5 degrees per minute double minuteAngle = minutes * 6; // 360 degrees / 60 minutes = 6 degrees per minute // Calculate the difference between the two angles double angle = hourAngle - minuteAngle; // Calculate absolute value without using Math.Abs if (angle 180) { angle = 360 - angle; } // Output the result Console.WriteLine($"The angle between the hour and minute hands is {angle} degrees."); } }
Check out your Company Bowl for anonymous work chats.