Convert seconds to hour, minute and seconds in C
scanf() - Question 17
In this question, we will see how to input total time in seconds in C programming using the scanf() function and print the time in hours, minutes and seconds. To know more about scanf() function click on the scanf() function lesson.
Q17) Write a program in C to input total time in seconds and print the time in hours, minutes and seconds.
Total Seconds: 4206
Hour: 1
Minutes: 10
Seconds: 6
Program
#include <stdio.h>
#include <conio.h>
int main()
{
int h,m,s,ts;
printf("Enter total seconds ");
scanf("%d",&ts);
h=ts/3600;
m=(ts%3600)/60;
s=(ts%3600)%60;
printf("Hours=%d\n",h);
printf("Minutes=%d\n",m);
printf("Seconds=%d",s);
return 0;
}
Output
Enter total seconds 4830 Hours=1 Minutes=20 Seconds=30