Question

Write a C program to converts a number of seconds to days, minutes, hours, and seconds....

Write a C program to converts a number of seconds to days, minutes, hours, and seconds.

Variables

days

minutes

hours

seconds

Execution sample

How many seconds? 234567

Days:      2

Hours:     17

Minutes:   9

Seconds:   27

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<stdio.h>

int main()
{
//Variable to store total seconds input from the user
unsigned int total_seconds;
// Variable to store remaining seconds after removing whole hours minutes and seconds
unsigned int rem_seconds;

// Prompt the user for seconds
printf("How many seconds?");
// Scanf is used to read the input from the user.
scanf("%u", &total_seconds);

// Get the number of days by dividing the total seconds by the number of seconds in a day i.e 24*60*60
printf("Days: %u\n", total_seconds/(60 * 60 * 24));
// Get the remaining seconds after removing all the whole days calculated before by getting the
// remainder value after division
rem_seconds = total_seconds % ( 60 * 60 * 24 );
// Get the number of hourss by dividing the total remaining seconds by the number of seconds in a hour i.e 60*60
printf("Hours: %u\n", rem_seconds/( 60 * 60));
// Get the remaining seconds after removing all the whole hourss calculated before by getting the
// remainder value after division
rem_seconds = rem_seconds % (60 * 60);
// Get the number of minutes by dividing the total remaining seconds by the number of seconds in a minute i.e 60
printf("Minutes: %u\n", rem_seconds/60);
// Get the remaining seconds after removing all the whole minutes calculated before by getting the
// remainder value after division
rem_seconds = rem_seconds % 60;
// print the remaining seconds
printf("Seconds: %u\n", rem_seconds);
}

Add a comment
Know the answer?
Add Answer to:
Write a C program to converts a number of seconds to days, minutes, hours, and seconds....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • PYTHON Write a program that converts a total number of seconds to hours, minutes, and seconds....

    PYTHON Write a program that converts a total number of seconds to hours, minutes, and seconds. It should (1) prompt the user for input, (2) read an integer from the keyboard, (3) and calculate the result. For example, "5000 seconds = 1 hours, 23 minutes, and 20 seconds". Hint: Use the modulus operator.

  • Write a program that accepts a number of minutes and converts it both to hours and...

    Write a program that accepts a number of minutes and converts it both to hours and days. For example, 6000 minutes is 100.0 hours or 4.166666666666667 days. Grading Write your Java code in the area on the right. Use the Run button to compile and run the code. Clicking the Run Checks button will run pre- configured tests against your code to calculate a grade.

  • Python (Convert milliseconds to hours, minutes, and seconds) Write a function that converts milliseconds to hours,...

    Python (Convert milliseconds to hours, minutes, and seconds) Write a function that converts milliseconds to hours, minutes, and seconds using the following header: def convertMillis(millis): The function returns a string as hours:minutes:seconds. For example, convertMillis(5500) returns the string 0:0:5, convertMillis(100000) returns the string 0:1:40, and convertMillis(555550000) returns the string 154:19:10. Write a test program that prompts the user to enter a value for milliseconds and displays a string in the format of hours:minutes:seconds. Sample Run Enter time in milliseconds: 555550000...

  • Write a program in which the user is asked to enter, a number of years, days,...

    Write a program in which the user is asked to enter, a number of years, days, hours, minutes and seconds. The program should convert it to seconds. For example, your program should find out how many total seconds are there in 1 year. 135 days, 95 hours, 230 minutes and 60000 seconds. Please write program using Python.

  • C++ Question 6 (10pt): Convert seconds Write a program that takes a number of seconds as...

    C++ Question 6 (10pt): Convert seconds Write a program that takes a number of seconds as user input (as an integer) and converts it to hours, minutes, and seconds as shown below. You should convert the amount of time in such a way that maximizes the whole numbers of hours and minutes. Expected output 1 (bold is user input) Enter a number of seconds: 60 0 hour(s) 1 minute(s) 0 second(s) Expected output 2 (bold is user input) Enter a...

  • Time can be expressed in [hours, minutes, seconds]. Create a program in C++ that takes a...

    Time can be expressed in [hours, minutes, seconds]. Create a program in C++ that takes a current time and adds an elapsed time to compute the future time. NOTE: hours are expressed using the 24 hours clock. For example, if the current time is 17, 34, 56 and the elapsed time is 9, 48, 17 then the future time is 3, 23, 13. You should have variables cth, ctm, cts, eth, etm, ets, fth, ftm, fts, representing the current/elapsed/future hours/minutes/seconds.

  • Write a C program convert.c that converts each number in an array by the sum of...

    Write a C program convert.c that converts each number in an array by the sum of that number plus 6 modulus 10. A sample input/output: Enter the length of the array: 5 Enter the elements of the array: 3 928 4 14 77 Output: 9 4 0 0 3 The program should include the following function: void convert(int *a1, int n, int *a2) The function converts every element in array a1 of length n to an output array a2. The...

  • Question 16 1 pts Convert 365 days (1 year) to hours, to minutes, to seconds, to...

    Question 16 1 pts Convert 365 days (1 year) to hours, to minutes, to seconds, to determine how many seconds there are in a year. Express the answer in scientific notation. 1.314 x 10 seconds 5.256 x 105 seconds 1.0512 x 10 seconds 3.1536 x 10 seconds Question 17 1 pts SI

  • Write a program that asks the user to enter a number ofseconds.• There are...

    Starting Out with C++ (9th Edition)  Chapter 4, Problem 7PCWrite a program that asks the user to enter a number of seconds.• There are 86400 seconds in a day. If the number of seconds entered by the user is greater than or equal to 86400, the program should display the number of days in that many seconds.• There are 3600 seconds in an hour. If the number of seconds entered by the user is less than 86400, but is greater...

  • in C++ Write a program that converts a time in 12-hour format to 24-hour format. The...

    in C++ Write a program that converts a time in 12-hour format to 24-hour format. The program will prompt the user to enter a time in HH:MM:SS AM/PM form. (The time must be entered exactly in this format all on one line.) It will then convert the time to 24 hour form. You may use a string type to read in the entire time at once including the space or you may choose to use separate variables for the hours,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT