The Program in C that prints the total seconds in a given time (hrs, min, sec) is given below:
#include <stdio.h>
int main() {
int hours, minutes, seconds, total_seconds;
printf("Enter the number of hours: ");
scanf("%d", &hours);
printf("Enter the number of minutes: ");
scanf("%d", &minutes);
printf("Enter the number of seconds: ");
scanf("%d", &seconds);
total_seconds = (hours * 3600) + (minutes * 60) + seconds; //calculating total seconds
printf("The total number of seconds in %d hours, %d minutes, and %d seconds is %d",
hours, minutes, seconds, total_seconds);
return 0;
}
Output:
Enter the number of hours: 12
Enter the number of minutes: 12
Enter the number of seconds: 12
The total number of seconds in 12 hours, 12 minutes, and 12 seconds is 43932
Pro-Tips💡
This program takes input of hours, minutes, and seconds and then it calculates the total seconds by multiplying hours by 3600 (the number of seconds in an hour),
minutes with 60 (number of seconds in a minute) and then adding the seconds.
Learn C-Sharp ↗
C-sharp covers every topic to learn about C-Sharp thoroughly.
Learn C Programming ↗
C-Programming covers every topic to learn about C-Sharp thoroughly.
Learn C++ Programming↗
C++ covers every topic to learn about C-Sharp thoroughly.