C++ 程序,将小时转换为分钟和秒


输入小时,任务是将小时数转换为分钟和秒并显示相应的结果

用于将小时转换为分钟和秒的公式是

1 hour = 60 minutes
   Minutes = hours * 60
1 hour = 3600 seconds
   Seconds = hours * 3600

示例

Input-: hours = 3
Output-: 3 hours in minutes are 180
   3 hours in seconds are 10800
Input-: hours = 5
Output-: 5 hours in minutes are 300
   5 hours in seconds are 18000

以下程序中使用的方法如下

  • 在整数变量(假设为 n)中输入小时数
  • 应用上面给出的转换公式,将小时转换为分钟和秒
  • 显示结果

算法

START
Step 1-> declare function to convert hours into minutes and seconds
   void convert(int hours)
   declare long long int minutes, seconds
   set minutes = hours * 60
   set seconds = hours * 3600
   print minute and seconds
step 2-> In main()
   declare variable as int hours = 3
   Call convert(hours)
STOP

示例

#include <bits/stdc++.h>
using namespace std;
//convert hours into minutes and seconds
void convert(int hours) {
    long long int minutes, seconds;
    minutes = hours * 60;
    seconds = hours * 3600;
    cout<<hours<<" hours in minutes are "<<minutes<<endl<<hours<<" hours in seconds are "<<seconds;
}
int main() {
    int hours = 3;
    convert(hours);
    return 0;
}

输出

3 hours in minutes are 180
3 hours in seconds are 10800

更新于: 09-Jul-2020

1K+ 浏览量

开启您的 职业

完成课程即可获得认证

开始
广告