给定整数n (小时数) ,任务是将其转换为分钟和秒。
例子:
Input: 5
Output: Minutes = 300, Seconds = 18000
Input: 2
Output: Minutes = 120, Seconds = 7200
方法:
- h小时= h * 60分钟,因为1小时= 60分钟。
- 类似地,小时数= h * 3600秒。
注意:要将m分钟转换为小时,请执行n / 60并持续s秒s / 3600 。
下面是上述方法的实现:
C++
// C++ program to convert hours
// into minutes and seconds
#include
using namespace std;
// Function to convert hours
// into minutes and seconds
void ConvertHours(int n)
{
long long int minutes, seconds;
minutes = n * 60;
seconds = n * 3600;
cout << "Minutes = " << minutes
<< ", Seconds = " << seconds << endl;
}
// Driver code
int main()
{
int n = 5;
ConvertHours(n);
return 0;
}
Java
// Java program to convert hours
// into minutes and seconds
import java.io.*;
class GFG {
// Function to convert hours
// into minutes and seconds
static void ConvertHours(int n)
{
int minutes, seconds;
minutes = n * 60;
seconds = n * 3600;
System.out.println( "Minutes = " + minutes
+ ", Seconds = " + seconds);
}
// Driver code
public static void main (String[] args) {
int n = 5;
ConvertHours(n);
}
}
// This code is contributed by inder_verma..
C#
// C# program to convert hours
// into minutes and seconds
using System;
class GFG
{
// Function to convert hours into
// minutes and seconds
static void ConvertHours(int n)
{
int minutes, seconds;
minutes = n * 60;
seconds = n * 3600;
Console.WriteLine("Minutes = " + minutes +
", Seconds = " + seconds);
}
// Driver code
public static void Main ()
{
int n = 5;
ConvertHours(n);
}
}
// This code is contributed by Ryuga
PHP
Python3
# C++ program to convert hours
# into minutes and seconds
# Function to convert hours
# into minutes and seconds
def ConvertHours(n):
minutes = n * 60;
seconds = n * 3600;
print("Minutes = ", minutes \
,", Seconds = " , seconds);
# Driver code
n = 5;
ConvertHours(n);
# This code contributed by Rajput-Ji
Javascript
输出:
Minutes = 300, Seconds = 18000
时间复杂度: O(1)
想要从精选的最佳视频中学习并解决问题,请查看有关从基础到高级C++的C++基础课程以及有关语言和STL的C++ STL课程。要完成从学习语言到DS Algo等的更多准备工作,请参阅“完整面试准备课程” 。