Advertisement
KingRayhan

c programming

Jun 2nd, 2015
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.73 KB | None | 0 0
  1. /*
  2. Program to Convert Time in Seconds to Hours, Minutes and Seconds
  3. */
  4. #include <stdio.h>
  5. main()
  6. {
  7. long sec, hr, min, t;
  8. printf("\nEnter time in seconds: ");
  9. scanf("%ld", &sec);
  10. hr = sec/3600;
  11. t = sec%3600;
  12. min = t/60;
  13. sec = t%60;
  14. printf("\n\nTime is %ld hrs %ld mins %ld secs", hr, min, sec);
  15. getch();
  16. }
  17. hr = sec/3600;
  18. This program follows the general logic of converting second to hour.ie divide the total second by 3600 thus we get the Hour,
  19.  t = sec%3600
  20. Then make a modular division on the total second ,thus we get the remaining seconds that can not form a hour.
  21. min = t/60;
  22. divide the 't' (seconds)with 60 ,then we get the remaining minutes.
  23. sec = t%60;
  24. modular division on the 't' result in the remaining seconds....
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement