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
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP