In: Computer Science
Include<stdio.h>
Write a program that prompts the user to input the elapsed time for an event in seconds.
The program then outputs the elapsed time in hours, minutes, and seconds.
For example:
Enter the elapsed time in second: 9630
The elapsed time in seconds = 9630
The equivalent time in hours:minutes:seconds = 02:40:30
Explanation::
Code in C is given below
Output is given at the end
Code in C::
#include <stdio.h>
int main(void) {
int seconds;
printf("Enter elapsed time in seconds:");
scanf("%d",&seconds);
printf("The elapsed time in seconds = %d\n",seconds);
int hours=seconds/3600;
int temp=seconds%3600;
int minutes=temp/60;
temp=temp%60;
printf("The equivalent time in hours:minutes:seconds = ");
if(hours<10){
printf("0%d:",hours);
}else{
printf("%d:",hours);
}
if(minutes<10){
printf("0%d:",minutes);
}else{
printf("%d:",minutes);
}
if(temp<10){
printf("0%d\n",temp);
}else{
printf("%d\n",temp);
}
return 0;
}
Output::
Enter elapsed time in seconds:9630
The elapsed time in seconds = 9630
The equivalent time in hours:minutes:seconds = 02:40:30