top of page

Ask a Question

Public·6 members

How to find the angle between hour and minute hands of a clock at any given time-C# Programming Help


 using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text; 
 namespace Questions
 { 
 class Program   
  { 
  static void Main(string[] args) 
         { 
          int hours, int mins
            /* input :- 9 30 output :- The angle between hour hand and minute 
            hand is 105 degrees         
           * input :- 13 30 output :- The angle between hour hand and minute 
            hand is 135 degrees*  */
  
        double hourDegrees = (hours * 30) + (mins * 30.0 / 60); 
        double minuteDegrees = mins * 6;  
         
           double diff = Math.Abs(hourDegrees - minuteDegrees);
             if (diff > 180)       
                  { 
                  diff = 360 - diff;   
                   }  
    Console.WriteLine("The angle between hour hand and minute hand is {0} 
    degrees", diff);  
       } 
     }
    }


109 Views
bottom of page