Advertisement
Guest User

Untitled

a guest
Dec 12th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. struct time
  4. {
  5. int hour;
  6. int minutes;
  7. int seconds;
  8. };
  9.  
  10.  
  11. int main()
  12. {
  13. int time_in_sec,hour,min,sec;
  14. struct time curr_time;
  15. do
  16. {
  17. printf("Give Hours - Minutes - Seconds : ");
  18. scanf("%d %d %d", &curr_time.hour, &curr_time.minutes, &curr_time.seconds);
  19. }
  20. while((curr_time.hour<0 || curr_time.hour>=12) || (curr_time.minutes<0 || curr_time.minutes>60) || (curr_time.seconds<0 || curr_time.seconds>60)); //elegxos timwn wste h wra pou dinei o xrhsths na einai swsth
  21.  
  22. time_in_sec=curr_time.hour*3600+curr_time.minutes*60+curr_time.seconds; // metatropi ths wra se second gia pio eukolh xrhsh
  23.  
  24. if(time_in_sec - 59 < 0)
  25. {
  26. int i = 0;
  27. int count = 0;
  28. while(i <= 59 && time_in_sec != 0)
  29. {
  30. time_in_sec = time_in_sec - 1;
  31. count = count + 1;
  32. i = i + 1;
  33. }
  34. time_in_sec = 11 * 3600 + 59 * 60 + 60;
  35. time_in_sec = time_in_sec - (59 - count);
  36. }
  37. else
  38. {
  39. time_in_sec = time_in_sec - 59;
  40. }
  41. hour = time_in_sec / 3600;
  42. min = time_in_sec % 3600 / 60;
  43. sec = time_in_sec % 3600 % 60;
  44. printf("%d : %d : %d", hour , min , sec);
  45. system("PAUSE");
  46. return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement