Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Program to Convert Time in Seconds to Hours, Minutes and Seconds
- */
- #include <stdio.h>
- main()
- {
- long sec, hr, min, t;
- printf("\nEnter time in seconds: ");
- scanf("%ld", &sec);
- hr = sec/3600;
- t = sec%3600;
- min = t/60;
- sec = t%60;
- printf("\n\nTime is %ld hrs %ld mins %ld secs", hr, min, sec);
- getch();
- }
- hr = sec/3600;
- This program follows the general logic of converting second to hour.ie divide the total second by 3600 thus we get the Hour,
- t = sec%3600
- Then make a modular division on the total second ,thus we get the remaining seconds that can not form a hour.
- min = t/60;
- divide the 't' (seconds)with 60 ,then we get the remaining minutes.
- sec = t%60;
- modular division on the 't' result in the remaining seconds....
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement