Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

⚡ Assignment 5: Extra solution #36

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions Assignment-05/assignment5-extra.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include <stdio.h>

int main(void) {
// initialize var
int seconds;
int remaining_seconds;
int mins;
int remaining_mins;
int hours;
int remaining_hours;
int days;

// get value for var
printf("Enter the amount of seconds: ");
scanf("%d", &seconds);

// initialize our arithmetic vars
remaining_seconds = seconds % 60; // 0 ~ 59
mins = seconds / 60;
remaining_mins = mins % 60; // 0 ~ 59
hours = mins / 60;
remaining_hours = hours % 24; // 0 ~ 23
days = hours / 24;

// Try more! Figure out months and years!
// Note: <https://en.wikipedia.org/wiki/Leap_year>
//
// If days and hours are both equal to 0,
// and I only want to display minutes and seconds, what should I do?

printf(
"%d seconds is equal to %d days, %d hours, %d minutes, and %d seconds.",
seconds, days, remaining_hours, remaining_mins, remaining_seconds);

return 0;
}