write a C program to Calculate the smallest angle between hour and minute hand of the clock , which shows the difference of time at a particular longitude and the time at UTC i.e. we have to take smaller of the two angle formed between hour and minute hand.
Answers
Answer:
The formula is
The minute hand takes 60 minute to covered 360 degree.
Therefore it takes one minute to covered 6 degree
As well as hour hand takes 12 hours to covered 360 degree
Therefore it takes one minute to covered 0.5 degree
#include <stdio.h>
#include <stdlib.h>
//This function is used to find the smallest angle between two hands
int smallest(int a, int b) { return (a < b)? a: b; }
int calculateAngle(double h, double m)
{
if (h <0 || m < 0 || h >12 || m > 60)
printf("Please Enter a Correct Input");
if (h == 12)
h = 0;
if (m == 60)
m = 0;
//Here we calculate the angle with respect to 12.00
int hour_angle = 0.5 * (h*60 + m);
int minute_angle = 6*m;
int angle = abs(hour_angle - minute_angle);
angle = smallest(360-angle, angle);
return angle;
}
int main()
{
printf("%d n", calculateAngle(9, 60));
printf("%d n", calculateAngle(3, 30));
return 0;
}