C代写:时间转换

给定的时间格式是以秒为单位, 要求输出human readbable的年月日格式。

Do the following programming problems. You will end up with at least one code file per problem. Submit your program source (and any other needed files) by sending mail to bmassing@cs.trinity.edu with each file as an attachment. Please use a subject line that mentions the course and the assignment (e.g., ``csci 1120 hw 2’’ or ``LL hw 2’’). You can develop your programs on any system that provides the needed functionality, but I will test them on one of the department’s Linux machines, so you should probably make sure they work in that environment before turning them in.

  1. (5 points) Write a C program to convert seconds into years, days, hours, minutes, and seconds. Your program should prompt the user for a number of seconds, get the number entered, and print the equivalent number of years, days, etc. (e.g., 100 seconds is 0 years, 0 days, 0 hours, 1 minute, and 40 seconds). Assume 365 days in a year (not quite right but makes the calculations simpler). For this assignment only, you do not need to do any kind of checking that what the user enters is actually an integer and non-negative, since we haven’t yet talked about conditional execution. Just assume it is and do the required calculations.

    Hints:

    • Probably the best way to do the required calculations is with the integer-division (/) and remainder (%) operators.
    • Be advised that a C-idiomatic way to define constants is with #define, e.g.,

      #define SECONDS_PER_MINUTE 60

      usually before the first function that uses them. This can help make code more human-readable.


Footnotes

… apply).1
Credit where credit is due: I based the wording of this list on a posting to a SIGCSE mailing list. SIGCSE is the ACM’s Special Interest Group on CS Education.


Berna Massingill
2017-09-05

kamisama wechat
KamiSama