C Program : Convert total seconds to hour, minute
#include <stdio.h>
int main() { int totalSeconds, hours, minutes, seconds; printf("Enter the total number of seconds: "); scanf("%d", &totalSeconds); if (totalSeconds >= 0) { hours = totalSeconds / 3600; // 1 hour = 3600 seconds totalSeconds %= 3600; // Calculate remaining seconds after calculating hours minutes = totalSeconds / 60; // 1 minute = 60 seconds seconds = totalSeconds % 60; // Calculate remaining seconds after calculating minutes printf("Hours: %d\n", hours); printf("Minutes: %d\n", minutes); printf("Seconds: %d\n", seconds); } else { printf("Invalid input. Please enter a non-negative value.\n"); } return 0; }
Comments
Post a Comment