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