Solve of URI 1019 (Time Conversion) in C & C++
How to solve:1. In this problem, we need to convert time in hour, minutes and seconds.
2. Input contains an integer, given as number of seconds.
3. First, we calculate hour by dividing input by 3600 as 1 hour contains 3600 seconds, and save reminder in temp variable.
4. Then, calculate minute by dividing temp by 60 as 1 minute contains 60 seconds.
5. And the reminder from minute is number of seconds.
6. Finally, print output as given format as problem description (HH:MM:SS).
See sample input and output for better understanding with printing output.
Go through problem description and see my solution for clear concept. Thanks. :)
Solution in C:
//URI online judge 1019 solution in C
//This solution is made by Mehedi Hasan Kajol
#include<stdio.h>
int main(void){
long int input, hour, minute, temp;
scanf(" %ld ", &input);
hour = input / 3600;
temp = input % 3600;
minute = temp / 60;
temp = temp % 60;
printf("%ld:%ld:%ld\n", hour, minute, temp);
return 0;
}
Solution in C++:
//URI online judge 1019 solution in C++
//This solution is made by Mehedi Hasan Kajol
#include<iostream>
using namespace std;
int main(void){
long int input, hour, minute, temp;
cin >> input;
hour = input / 3600;
temp = input % 3600;
minute = temp / 60;
temp = temp % 60;
cout << hour << ":" << minute << ":" << temp << endl;
return 0;
}