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

Showing Answers 1 - 3 of 3 Answers

Sathya Hadadi

  • Apr 28th, 2015
 

Answer in code part

Code
  1. #include <stdio.h>

  2. #include <string.h>

  3. #include <conio.h>

  4. #include <stdlib.h>

  5. #define MIN_PER_HOUR        60.0F

  6. #define SEC_PER_MIN         60.0F

  7. #define SEC_PER_HOUR        (MIN_PER_HOUR*SEC_PER_MIN)

  8. #define DEGREE_FOR_1_HOUR   (360.0F/12.0F)

  9. #define DEGREE_FOR_1_SEC    (DEGREE_FOR_1_HOUR/SEC_PER_HOUR)

  10.  

  11.  

  12. int main()

  13. {

  14.         char time1[10] = {0};

  15.         char time2[10] = {0};

  16.         printf("%f

  17. ",DEGREE_FOR_1_HOUR);

  18.         printf("%f

  19. ",DEGREE_FOR_1_SEC);

  20.  

  21.         printf("Enter first time in hh:mm:ss format

  22. ");

  23.         fflush(stdout);

  24.         scanf("%s", time1);

  25.  

  26.         printf("Enter second time in hh:mm:ss format

  27. ");

  28.         fflush(stdout);

  29.         scanf("%s", time2);

  30.  

  31.         if(strcmp(time1, time2) > 0)

  32.         {

  33.                 const char delimit[2] = ":";

  34.                 int hour1, hour2, min1, min2, sec1, sec2;

  35.                 char *token;

  36.                 printf("time 1 = %s is greater

  37. ", time1);

  38.  

  39.                 token = strtok(time1,delimit);

  40.                 hour1 = strtol(token, (char **)NULL, 10);

  41.                 printf("%d

  42. ",hour1);

  43.                 token = strtok(NULL,delimit);

  44.                 min1 = strtol(token, (char **)NULL, 10);

  45.                 printf("%d

  46. ",min1);

  47.                 token = strtok(NULL,delimit);

  48.                 sec1 = strtol(token, (char **)NULL, 10);

  49.                 printf("%d

  50. ",sec1);

  51.  

  52.                 token = strtok(time2,delimit);

  53.                 hour2 = strtol(token, (char **)NULL, 10);

  54.                 printf("%d

  55. ",hour2);

  56.                 token = strtok(NULL,delimit);

  57.                 min2 = strtol(token, (char **)NULL, 10);

  58.                 printf("%d

  59. ",min2);

  60.                 token = strtok(NULL,delimit);

  61.                 sec2 = strtol(token, (char **)NULL, 10);

  62.                 printf("%d

  63. ",sec2);

  64.  

  65.                 float total_sec1 = (hour1)*SEC_PER_HOUR + (min1)*SEC_PER_MIN + (sec1);

  66.                 float total_sec2 = (hour2)*SEC_PER_HOUR + (min2)*SEC_PER_MIN + (sec2);

  67.  

  68.                 float angle = (total_sec1 - total_sec2) * DEGREE_FOR_1_SEC;

  69.                 printf("%f

  70. ", angle);

  71.         }

  72.         else

  73.         {

  74.                 printf("time 2 = %s is greater", time2);

  75.         }

  76.  

  77. }

  78.  

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions