Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Dato: 17-09-2011
- * Kursus: Imperativ Programming
- * Underviser: Kurt Nørmark
- * Opgave: http://people.cs.aau.dk/~normark/impr-c/control-conditional-exp-slide-exercise-1.html
- */
- #include <stdio.h>
- #define SEC_PER_HOUR 3600
- #define SEC_PER_MIN 60
- int main()
- {
- // Initialiser variabler
- int total_seconds, rest, hours, minutes, seconds;
- // Få antal sekunder
- printf("Skriv et positivt antal sekunder: ");
- scanf("%d", &total_seconds);
- // Lav udregningerne.
- hours = total_seconds / SEC_PER_HOUR;
- rest = total_seconds % SEC_PER_HOUR;
- minutes = rest / SEC_PER_MIN;
- seconds = rest % SEC_PER_MIN;
- // Start på if statements
- if(total_seconds <= 0)
- {
- printf("Ikke godkendt.");
- return 0;
- }
- if(hours > 0)
- {
- if(hours == 1)
- {
- printf("%d time", hours);
- }
- else
- {
- printf("%d timer", hours);
- }
- if(minutes > 0 || seconds > 0)
- {
- if(minutes > 0 && seconds > 0)
- {
- printf(", ");
- }
- else
- {
- printf(" og ");
- }
- }
- }
- if(minutes > 0)
- {
- if(minutes == 1)
- {
- printf("%d minut", minutes);
- }
- else
- {
- printf("%d minutter", minutes);
- }
- if(seconds > 0)
- {
- printf(" og ");
- }
- }
- if(seconds > 0)
- {
- if(seconds == 1)
- {
- printf("%d sekund", seconds);
- }
- else
- {
- printf("%d sekunder", seconds);
- }
- }
- // Afslut.
- return 0;
- }
Add Comment
Please, Sign In to add comment