C Exercises: Convert a given integer to hours, minutes and seconds
C Basic Declarations and Expressions: Exercise-17 with Solution
Write a C program to convert a given integer (in seconds) to hours, minutes and seconds.
Pictorial Presentation:

C Code:
#include <stdio.h>
int main() {
int sec, h, m, s; // Declare variables for seconds, hours, minutes, and seconds
// Prompt user for input seconds and store in 'sec'
printf("Input seconds: ");
scanf("%d", &sec);
// Calculate hours, minutes, and remaining seconds
h = (sec/3600);
m = (sec -(3600*h))/60;
s = (sec -(3600*h)-(m*60));
// Print the time in format H:M:S
printf("H:M:S - %d:%d:%d\n",h,m,s);
return 0;
}
Sample Output:
Input seconds: 25300 H:M:S - 7:1:40
Flowchart:

C Programming Code Editor:
Previous: Write a C program to read an amount (integer value) and break the amount into smallest possible number of bank notes.
Next: Write a C program to convert a given integer (in days) to years, months and days, assumes that all months have 30 days and all years have 365 days.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join