Atheuz

Untitled

Sep 17th, 2011 (edited)
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.46 KB | None | 0 0
  1. /*
  2.  *  Dato: 17-09-2011
  3.  *  Kursus: Imperativ Programming
  4.  *  Underviser: Kurt Nørmark
  5.  *  Opgave: http://people.cs.aau.dk/~normark/impr-c/control-conditional-exp-slide-exercise-1.html
  6.  */
  7.  
  8. #include <stdio.h>
  9.  
  10. int main()
  11. {
  12.     int n, hours, minutes, seconds;
  13.  
  14.     printf("Skriv antal sekunder: ");
  15.     scanf("%d", &n);
  16.  
  17.     printf("%d sekunder svarer til ", n);
  18.  
  19.     hours = n / 3600;
  20.     n = n % 3600;
  21.  
  22.     minutes = n / 60;
  23.     n = n % 60;
  24.  
  25.     seconds = n;
  26.  
  27.     // TODO Skriver ikke 'og' eller kommaer som opgaven kræver.
  28.  
  29.     if(hours > 0)
  30.     {
  31.         if(hours == 1)
  32.         {
  33.             printf("%d time", hours);
  34.         }
  35.         else
  36.         {
  37.             printf("%d timer", hours);
  38.         }
  39.         if(minutes > 0 || seconds > 0)
  40.         {
  41.             if(minutes > 0 && seconds > 0)
  42.             {
  43.                 printf(", ");
  44.             }
  45.             else
  46.             {
  47.                 printf(" og ");
  48.             }
  49.         }
  50.     }
  51.  
  52.     if(minutes > 0)
  53.     {
  54.         if(minutes == 1)
  55.         {
  56.             printf("%d minut", minutes);
  57.         }
  58.         else
  59.         {
  60.             printf("%d minutter", minutes);
  61.         }
  62.         if(seconds > 0)
  63.         {
  64.             printf(" og ");
  65.         }
  66.     }
  67.  
  68.     if(seconds > 0)
  69.     {
  70.         if(seconds == 1)
  71.         {
  72.             printf("%d sekund", seconds);
  73.         }
  74.         else
  75.         {
  76.             printf("%d sekunder", seconds);
  77.         }
  78.     }
  79. }
Add Comment
Please, Sign In to add comment