 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Converting seconds into days, hours, minutes and seconds in C++
In this tutorial, we will be discussing a program to convert seconds into days, hours, minutes and seconds.
For this we will be provided with a random number of seconds. Our task is to convert it into proper number of days, hours, minutes and seconds respectively.
Example
#include <bits/stdc++.h> using namespace std; //converting into proper format void convert_decimal(int n) {    int day = n / (24 * 3600);    n = n % (24 * 3600);    int hour = n / 3600;    n %= 3600;    int minutes = n / 60 ;    n %= 60;    int seconds = n;    cout << day << " " << "days " << hour    << " " << "hours " << minutes << " "    << "minutes " << seconds << " "    << "seconds " << endl; } int main(){    int n = 126700;    convert_decimal(n);    return 0; }  Output
1 days 11 hours 11 minutes 40 seconds
Advertisements
 