Skip to content

Instantly share code, notes, and snippets.

@oykelrae
Last active December 9, 2019 22:23
Show Gist options
  • Save oykelrae/1ed485c2cd8786548f6fd9893422d4a2 to your computer and use it in GitHub Desktop.
Save oykelrae/1ed485c2cd8786548f6fd9893422d4a2 to your computer and use it in GitHub Desktop.
Convert seconds to hh:mm:ss format
Enter the number of seconds elapsed today: 65434
The time is 18:10:34
Program ended with exit code: 0
#include <stdio.h>
#include <math.h>
int main() {
int s, h, m, sec;
printf("Enter the number of seconds elapsed today: ");
scanf("%d", &s);
h = s / pow(60, 2);
m = (s - h * 60 * 60 ) / 60;
sec = s % 60;
printf("The time is %d:%d:%d\n", h, m, sec);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment