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>
- int main()
- {
- int n, hours, minutes, seconds;
- printf("Skriv antal sekunder: ");
- scanf("%d", &n);
- printf("%d sekunder svarer til ", n);
- hours = n / 3600;
- n = n % 3600;
- minutes = n / 60;
- n = n % 60;
- seconds = n;
- // TODO Skriver ikke 'og' eller kommaer som opgaven kræver.
- 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);
- }
- }
- }
Add Comment
Please, Sign In to add comment