Advertisement
Qrist

Calculate the angle between hour and minute

Apr 24th, 2020
335
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.69 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using static System.Console;
  4.  
  5. class Program
  6. {
  7.     public static void Main(string[] args)
  8.     {
  9.         Console.WriteLine(calcAngle(6,00));
  10.     }
  11.  
  12.     static int calcAngle(double h,double m)
  13.     {
  14.         if(h<0 || m<0 || h>12 || m>60)
  15.         {
  16.             Console.Write("Wrong");
  17.         }
  18.         if(h==12)
  19.         {
  20.             h = 0;
  21.         }
  22.         if(m==60)
  23.         {
  24.             m = 0;
  25.         }
  26.         int hourangle = (int)(0.5 * (h * 60 + m));
  27.         int minuteangle = (int)(6 * m);
  28.         int angle = Math.Abs(hourangle - minuteangle);
  29.         angle = Math.Min(360 - angle, angle);
  30.         return angle;
  31.     }    
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement