++ Homework 2 Files
This commit is contained in:
parent
90652a17ce
commit
6269fbc4ce
10 changed files with 191 additions and 0 deletions
40
Homework2/dhms.c
Normal file
40
Homework2/dhms.c
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
// header files
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
// local constants
|
||||
#define SECONDS_IN_DAY 86400
|
||||
#define SECONDS_IN_HOUR 3600
|
||||
#define SECONDS_IN_MINUTE 60
|
||||
|
||||
#define TIME_CONSTANT_SECONDS 8675309
|
||||
|
||||
/*
|
||||
Name: Day/Hour/Minute/Second Calculator
|
||||
Process: Given a number of seconds,
|
||||
figure out how many days, hours, minutes and seconds fits.
|
||||
Function input/parameters: NONE
|
||||
Function output/parameters: NONE
|
||||
Function output/returned: NONE
|
||||
Device input/---: NONE
|
||||
Device output/---: NONE
|
||||
Dependencies: included by standard libraries
|
||||
*/
|
||||
int main()
|
||||
{
|
||||
// define local variables
|
||||
int totalDays, totalHours, totalMinutes, totalSeconds;
|
||||
// do calculations
|
||||
// need to modulo then divide by last time unit for each part.
|
||||
totalSeconds = TIME_CONSTANT_SECONDS % SECONDS_IN_MINUTE;
|
||||
totalMinutes = (TIME_CONSTANT_SECONDS % SECONDS_IN_HOUR) / SECONDS_IN_MINUTE;
|
||||
totalHours = (TIME_CONSTANT_SECONDS % SECONDS_IN_DAY) / SECONDS_IN_HOUR;
|
||||
totalDays = (TIME_CONSTANT_SECONDS % (SECONDS_IN_DAY * 30)) / SECONDS_IN_DAY;
|
||||
// display results
|
||||
printf("In %d seconds, there are: %d days, %d hours, %d minutes, %d seconds\n",
|
||||
TIME_CONSTANT_SECONDS, totalDays, totalHours, totalMinutes, totalSeconds);
|
||||
// return success
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue