How to find the angle between hour and minute hands of a clock at any given time?
Loading
How to find the angle between hour and minute hands of a clock at any given time?
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Vishal YelveRank #178 · 13.6K reputationPosted Nov 7, 2022, 9:19 AM EST
// C# program to find the angle between // hour and minute hands using System; class Angle { // Function to calculate the angle static int calcAngle(double h, double m) { // validate the input if (h 12 || m > 60) Console.Write("Wrong input"); if (h == 12) h = 0; if (m == 60) { m = 0; h += 1; if(h>12) h = h-12; } // Calculate the angles moved by hour and // minute hands with reference to 12:00 int hour_angle = (int)(0.5 * (h * 60 + m)); int minute_angle = (int)(6 * m); // Find the difference between two angles int angle = Math.Abs(hour_angle - minute_angle); // smaller angle of two possible angles angle = Math.Min(360 - angle, angle); return angle; } // Driver code public static void Main () { Console.WriteLine(calcAngle(9, 60)); Console.Write(calcAngle(3, 30)); } } // Output 60 75Toufik El AzzaouiRank #3,804 · 389 reputationPosted Nov 7, 2022, 9:33 AM EST
public int getAngle(int Hours,int Minutes) { return Math.Abs(Hours-Minutes)*30; }Pankajkumar PatelRank #181 · 13.4K reputationPosted Nov 8, 2022, 2:01 AM EST
Hi Guest User,
One can find the angle between hour and minute hands of a clock in C# as following:
int h=2, m=20; double angle = (System.Math.Abs(((60*h-11*m)/2.0)) > 180) ? (360 - System.Math.Abs(((60*h-11*m)/2.0))) : (System.Math.Abs(((60*h-11*m)/2.0))); Console.WriteLine(angle);For more details:
https://en.wikipedia.org/wiki/Clock_angle_problem
Hope, this will help you!