C program to convert keyboard inputted seconds into days, hours, minutes and seconds.
Program:
#include<stdio.h>
int main()
{
int sec;
int min,hrs,days,temp;
printf("Total seconds: ");
scanf("%d",&sec);
days=(sec/86400);
temp= sec%86400;
hrs=temp/3600;
temp=temp%3600;
min=temp/60;
sec=temp%60;
printf("days: %d\t hours: %d\t minutes: %d\t seconds: %d",days,hrs,min,sec);
return 0;
}
int main()
{
int sec;
int min,hrs,days,temp;
printf("Total seconds: ");
scanf("%d",&sec);
days=(sec/86400);
temp= sec%86400;
hrs=temp/3600;
temp=temp%3600;
min=temp/60;
sec=temp%60;
printf("days: %d\t hours: %d\t minutes: %d\t seconds: %d",days,hrs,min,sec);
return 0;
}
Sample input:
Total seconds: 86462
Output:
days: 1 hours: 0 minutes: 1 seconds: 2
No comments:
Post a Comment