กำหนดโดยป้อนข้อมูลเป็นชั่วโมงและงานคือการแปลงจำนวนชั่วโมงเป็นนาทีและวินาทีและแสดงผลที่เกี่ยวข้อง
สูตรที่ใช้ในการแปลงชั่วโมงเป็นนาทีและวินาทีคือ −
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