Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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(" ");
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote