C++ Program for converting hours into minutes and seconds



Given with the input as hours and the task is to convert the number of hours into minutes and seconds and display the corresponding result

Formula used for converting the hours into minutes and seconds is

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

Example

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

Approach used in the below program is as follows

  • Input the number of hours in an integer variable let’s say n
  • Apply the formula of conversion given above to convert hours into minutes and seconds
  • Display the result

Algorithm

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

Example

#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; }

Output

3 hours in minutes are 180 3 hours in seconds are 10800
Updated on: 2020-07-09T08:23:37+05:30

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements