Advertisement
LessVegetables

Часики

Mar 11th, 2023
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.09 KB | None | 0 0
  1. // Часики
  2. // hw due 22.02.2023
  3. // Задано время. Определить время до ближайшей встречи часовой и минутной стрелки
  4.  
  5. #include <stdio.h>
  6.  
  7. int main()
  8. {
  9.     double hour, minute;
  10.     printf("Enter the time:\t");
  11.  
  12.     scanf("%lf %lf", &hour, &minute);
  13.  
  14.     if (hour > 11){ hour -= 12;}
  15.     minute += hour * 60;
  16.     if (minute > 719){ minute -= 720;}
  17.  
  18.     double matched[] = {0.0, (1.0 + 1.0/11.0)*60, (2.0 + 2.0/11.0)*60, (3.0 + 3.0/11.0)*60, (4.0 + 4.0/11.0)*60, (5.0 + 5.0/11.0)*60, (6.0 + 6.0/11.0)*60, (7.0 + 7.0/11.0)*60, (8.0 + 8.0/11.0)*60, (9.0 + 9.0/11.0)*60, (10.0 + 10.0/11.0)*60, 720.0};
  19.  
  20.     int timeAdded = 0;
  21.     for (int i = 0; i < 13; i++)
  22.     {
  23.         if (matched[i] - minute >= 0)
  24.         {
  25.             timeAdded = matched[i] - minute;
  26.             break;
  27.         }
  28.     }
  29.  
  30.     if (timeAdded)
  31.     {
  32.         printf("In %d hours %d minutes, the hands will meet up!", timeAdded / 60, timeAdded % 60);
  33.     }
  34.     else
  35.     {
  36.         printf("The hads are already matched up!");
  37.     }
  38.     return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement