0

hello everyone,I must solve a problem which effect my c programming lesson grade...Here is the problem:
Write a program to convert a time given seconds to hours,minutes and seconds format.

Sample Run:
Enter seconds: 8230
It is 2 hours, 17 minutes ,10 seconds…

We learned only #include<stdio.h> not iostream or other.Thanks in advance.

3
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by mrtsoftware
0

You can use the division operator / to extract the number of hours and minutes. How many seconds in an hour? How many in one minute?

8230 / (60 * 60) = number of hours

0

Yeah, but this is a C++ forum. :)
Little help: 1 hour = 60*60 seconds = 3600secs.

First you have to store the amount of seconds that can't be converted to hours.
8230 % 3600 = 1030. You store the reminder in a temporary variable, then divide 8230 by 3600.
8230 / 3600 = 2 hours( int ).
Now you have to convert the remaining seconds (1030) to minutes. You store the remaining seconds that can't be converted to minutes in a temporary variable. 1030 % 60 = 10. Now calculate the minutes: 1030 / 60 = 17.

Put all it together and your time will be 2 hours 17 minutes 10 seconds. You can check the result by adding them together. 2*3600 + 17*60 + 10 = 7200 + 1020 +10 = 8230

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.