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 将小时转换为分钟和秒 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; //将小时转换为分钟和秒 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