# How to find angle between hands of clock between old time and new time?

Input1: 02:45:56 (string)
input2: 03:06:17 (string)
output:
1) angle between the old position of hour hand and new position of hour hand
2) angle between the old position of minute hand and new position of minute hand
3) angle between the old position of second hand and new position of second hand

• Apr 28th, 2015

```Code#include <stdio.h>
#include <string.h>
#include <conio.h>
#include <stdlib.h>
#define MIN_PER_HOUR        60.0F
#define SEC_PER_MIN         60.0F
#define SEC_PER_HOUR        (MIN_PER_HOUR*SEC_PER_MIN)
#define DEGREE_FOR_1_HOUR   (360.0F/12.0F)
#define DEGREE_FOR_1_SEC    (DEGREE_FOR_1_HOUR/SEC_PER_HOUR)

int main()
{
char time1 = {0};
char time2 = {0};
printf("%f
",DEGREE_FOR_1_HOUR);
printf("%f
",DEGREE_FOR_1_SEC);

printf("Enter first time in hh:mm:ss format
");
fflush(stdout);
scanf("%s", time1);

printf("Enter second time in hh:mm:ss format
");
fflush(stdout);
scanf("%s", time2);

if(strcmp(time1, time2) > 0)
{
const char delimit = ":";
int hour1, hour2, min1, min2, sec1, sec2;
char *token;
printf("time 1 = %s is greater
", time1);

token = strtok(time1,delimit);
hour1 = strtol(token, (char **)NULL, 10);
printf("%d
",hour1);
token = strtok(NULL,delimit);
min1 = strtol(token, (char **)NULL, 10);
printf("%d
",min1);
token = strtok(NULL,delimit);
sec1 = strtol(token, (char **)NULL, 10);
printf("%d
",sec1);

token = strtok(time2,delimit);
hour2 = strtol(token, (char **)NULL, 10);
printf("%d
",hour2);
token = strtok(NULL,delimit);
min2 = strtol(token, (char **)NULL, 10);
printf("%d
",min2);
token = strtok(NULL,delimit);
sec2 = strtol(token, (char **)NULL, 10);
printf("%d
",sec2);

float total_sec1 = (hour1)*SEC_PER_HOUR + (min1)*SEC_PER_MIN + (sec1);
float total_sec2 = (hour2)*SEC_PER_HOUR + (min2)*SEC_PER_MIN + (sec2);

float angle = (total_sec1 - total_sec2) * DEGREE_FOR_1_SEC;
printf("%f
", angle);
}
else
{
printf("time 2 = %s is greater", time2);
}

}
```  