Program to find the time remaining for the day to complete
Given the current time in the form of HH::MM, where H represents the hours and M, represents the minutes in a 24-hour time format. The task is to calculate the time remaining for the day to complete as HH::MM.
Examples:
Input: HH::MM = 00::01
Output: 23::01
Input: HH::MM = 23::55
Output: 00::05
Approach:
- Since the total minutes in a 24 hour complete day is 24 * 60 = 1440 minutes
- Calculate the time completed in minutes
- Calculate the time remaining in the form of minutes as total minutes – time completed
- Convert the time remaining in the form of HH::MM
Below is the implementation of the above approach:
CPP
#include <bits/stdc++.h>
using namespace std;
void remainingTime( int h, int m)
{
int totalMin, hoursRemaining, minRemaining;
totalMin = 1440 - 60 * h - m;
hoursRemaining = totalMin / 60;
minRemaining = totalMin % 60;
cout << hoursRemaining << "::"
<< minRemaining << endl;
}
int main()
{
int h = 0, m = 1;
remainingTime(h, m);
return 0;
}
|
Java
class GFG
{
static void remainingTime( int h, int m)
{
int totalMin, hoursRemaining, minRemaining;
totalMin = 1440 - 60 * h - m;
hoursRemaining = totalMin / 60 ;
minRemaining = totalMin % 60 ;
System.out.print(hoursRemaining+ "::"
+ minRemaining + "\n" );
}
public static void main(String[] args)
{
int h = 0 , m = 1 ;
remainingTime(h, m);
}
}
|
Python
def remainingTime(h, m):
totalMin = 1440 - 60 * h - m
hoursRemaining = totalMin / / 60
minRemaining = totalMin % 60
print (hoursRemaining, "::" ,minRemaining)
h = 0
m = 1
remainingTime(h, m)
|
C#
using System;
class GFG
{
static void remainingTime( int h, int m)
{
int totalMin, hoursRemaining, minRemaining;
totalMin = 1440 - 60 * h - m;
hoursRemaining = totalMin / 60;
minRemaining = totalMin % 60;
Console.WriteLine(hoursRemaining+ "::"
+ minRemaining);
}
public static void Main()
{
int h = 0, m = 1;
remainingTime(h, m);
}
}
|
Javascript
<script>
function remainingTime(h, m)
{
var totalMin, hoursRemaining, minRemaining;
totalMin = 1440 - 60 * h - m;
hoursRemaining = totalMin / 60;
minRemaining = totalMin % 60;
document.write(Math.trunc(hoursRemaining)+
"::" + minRemaining);
}
var h = 0, m = 1;
remainingTime(h, m);
</script>
|
Time Complexity: O(1)
Auxiliary Space: O(1)
Last Updated :
31 May, 2022
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...