C Program to Convert Hours into Minutes and Seconds
Given an integer n which is the number of hours, the task is to convert it into minutes and seconds.
Examples:Â
Input: 5Â
Output: Minutes = 300, Seconds = 18000
Input: 2Â
Output: Minutes = 120, Seconds = 7200Â
Approach:Â
Â
- h hours = h * 60 minutes as 1 hour = 60 minutes.
- Similarly h hours = h * 3600 seconds.
Note: To convert m minutes back into hours, do n / 60 and for s seconds s / 3600.
Below is the implementation of the above approach:Â
Â
C
#include <stdio.h>
void ConvertHours( int n)
{
long long int minutes, seconds;
minutes = n * 60;
seconds = n * 3600;
printf ("Minutes = %lld, Seconds = %lld
",minutes,seconds);
}
int main()
{
int n = 5;
ConvertHours(n);
return 0;
}
|
Output:Â
Minutes = 300, Seconds = 18000
Â
Time Complexity : O(1)
Auxiliary Space: O(1)
Last Updated :
26 Oct, 2022
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...