Write a C program that asks the user to enter a number of seconds, then replies
ID: 673017 • Letter: W
Question
Write a C program that asks the user to enter a number of seconds, then replies with the time in different units, depending on the amount entered:
if the number is less than 60, print the number entered followed by “seconds”
if the number is 60 or more, but less than 3600, print the number of minutes followed by “minutes” - note, we are dealing in rough numbers here – if the user enters 75, the result
should be “1 minute”
if the number is 3600 or more, but less than 86400, print the number of hours followed
by “hours”
if the number is 86400 or more, print the number of days followed by “days”
Explanation / Answer
Please find the required solution:
#include<stdio.h>
#include<conio.h>
main()
{
int seconds;
printf("Enter number of seconds:");
scanf("%d",&seconds);
//print in seconds
if(seconds>0 && seconds<60)
{
printf("%d seconds",seconds);
}
//print in minutes
else if(seconds>=60 && seconds<3600)
{
printf("%d minutes",seconds/60);
}
//print in hours
else if(seconds>3600 && seconds<86400)
{
printf("%d hours",seconds/3600);
}
//print in days
else if(seconds>=86400)
{
printf("%d days",seconds/86400);
}
printf(" ");
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.