From b17e06a9e3377e8dd614187cf5bd21664bd508c5 Mon Sep 17 00:00:00 2001
From: Peter Gerwinski <peter.gerwinski@hs-bochum.de>
Date: Mon, 23 Nov 2015 20:44:54 +0100
Subject: [PATCH] =?UTF-8?q?Musterl=C3=B6sung=20f=C3=BCr=20=C3=9Cbungsaufga?=
 =?UTF-8?q?be=202=20vom=2019.11.2015?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 20151126/aufgabe-2.c   | 42 ++++++++++++++++++++++++++++++++++++++++
 20151126/loesung-2-0.c | 44 ++++++++++++++++++++++++++++++++++++++++++
 20151126/loesung-2-1.c | 39 +++++++++++++++++++++++++++++++++++++
 20151126/loesung-2-2.c | 42 ++++++++++++++++++++++++++++++++++++++++
 20151126/loesung-2-3.c | 40 ++++++++++++++++++++++++++++++++++++++
 5 files changed, 207 insertions(+)
 create mode 100644 20151126/aufgabe-2.c
 create mode 100644 20151126/loesung-2-0.c
 create mode 100644 20151126/loesung-2-1.c
 create mode 100644 20151126/loesung-2-2.c
 create mode 100644 20151126/loesung-2-3.c

diff --git a/20151126/aufgabe-2.c b/20151126/aufgabe-2.c
new file mode 100644
index 0000000..896d26a
--- /dev/null
+++ b/20151126/aufgabe-2.c
@@ -0,0 +1,42 @@
+#include <stdio.h>
+
+#define ORIGINYEAR 1980
+
+int IsLeapYear (int year)
+{
+  if (year % 4)
+    return 0;
+  else if (year % 100)
+    return 1;
+  else if (year % 400)
+    return 0;
+  else
+    return 1;
+}
+
+int main (void)
+{
+  int days = (2008 - ORIGINYEAR) * 365 + 8 + 365;  /* 2008-12-31 */
+
+  int year = ORIGINYEAR;
+
+  while (days > 365)
+    {
+      if (IsLeapYear (year))
+        {
+          if (days > 366)
+            {
+              days -= 366;
+              year += 1;
+            }
+        }
+      else
+        {
+          days -= 365;
+          year += 1;
+        }
+    }
+
+  printf ("day #%d in the year %d\n", days, year);
+  return 0;
+}
diff --git a/20151126/loesung-2-0.c b/20151126/loesung-2-0.c
new file mode 100644
index 0000000..bfc5bd2
--- /dev/null
+++ b/20151126/loesung-2-0.c
@@ -0,0 +1,44 @@
+#include <stdio.h>
+
+#define ORIGINYEAR 1980
+
+int IsLeapYear (int year)
+{
+  if (year % 4)
+    return 0;
+  else if (year % 100)
+    return 1;
+  else if (year % 400)
+    return 0;
+  else
+    return 1;
+}
+
+int main (void)
+{
+  int days = (2008 - ORIGINYEAR) * 365 + 8 + 365;  /* 2008-12-31 */
+
+  int year = ORIGINYEAR;
+
+  while (days > 365)
+    {
+      if (IsLeapYear (year))
+        {
+          if (days > 366)
+            {
+              days -= 366;
+              year += 1;
+            }
+          else
+            break;
+        }
+      else
+        {
+          days -= 365;
+          year += 1;
+        }
+    }
+
+  printf ("day #%d in the year %d\n", days, year);
+  return 0;
+}
diff --git a/20151126/loesung-2-1.c b/20151126/loesung-2-1.c
new file mode 100644
index 0000000..d061c64
--- /dev/null
+++ b/20151126/loesung-2-1.c
@@ -0,0 +1,39 @@
+#include <stdio.h>
+
+#define ORIGINYEAR 1980
+
+int IsLeapYear (int year)
+{
+  if (year % 4)
+    return 0;
+  else if (year % 100)
+    return 1;
+  else if (year % 400)
+    return 0;
+  else
+    return 1;
+}
+
+int DaysInYear (int year)
+{
+  if (IsLeapYear (year))
+    return 366;
+  else
+    return 365;
+}
+
+int main (void)
+{
+  int days = (2008 - ORIGINYEAR) * 365 + 8 + 365;  /* 2008-12-31 */
+
+  int year = ORIGINYEAR;
+
+  while (days > DaysInYear (year))
+    {
+      days -= DaysInYear (year);
+      year += 1;
+    }
+
+  printf ("day #%d in the year %d\n", days, year);
+  return 0;
+}
diff --git a/20151126/loesung-2-2.c b/20151126/loesung-2-2.c
new file mode 100644
index 0000000..d3af87c
--- /dev/null
+++ b/20151126/loesung-2-2.c
@@ -0,0 +1,42 @@
+#include <stdio.h>
+
+#define ORIGINYEAR 1980
+
+int IsLeapYear (int year)
+{
+  if (year % 4)
+    return 0;
+  else if (year % 100)
+    return 1;
+  else if (year % 400)
+    return 0;
+  else
+    return 1;
+}
+
+int DaysInYear (int year)
+{
+  if (IsLeapYear (year))
+    return 366;
+  else
+    return 365;
+}
+
+int main (void)
+{
+  int days = (2008 - ORIGINYEAR) * 365 + 8 + 365;  /* 2008-12-31 */
+
+  int year = ORIGINYEAR;
+  int days_in_year;
+
+  days_in_year = DaysInYear (year);
+  while (days > days_in_year)
+    {
+      days -= days_in_year;
+      year += 1;
+      days_in_year = DaysInYear (year);
+    }
+
+  printf ("day #%d in the year %d\n", days, year);
+  return 0;
+}
diff --git a/20151126/loesung-2-3.c b/20151126/loesung-2-3.c
new file mode 100644
index 0000000..5a0e6e4
--- /dev/null
+++ b/20151126/loesung-2-3.c
@@ -0,0 +1,40 @@
+#include <stdio.h>
+
+#define ORIGINYEAR 1980
+
+int IsLeapYear (int year)
+{
+  if (year % 4)
+    return 0;
+  else if (year % 100)
+    return 1;
+  else if (year % 400)
+    return 0;
+  else
+    return 1;
+}
+
+int DaysInYear (int year)
+{
+  if (IsLeapYear (year))
+    return 366;
+  else
+    return 365;
+}
+
+int main (void)
+{
+  int days = (2008 - ORIGINYEAR) * 365 + 8 + 365;  /* 2008-12-31 */
+
+  int year = ORIGINYEAR;
+  int days_in_year;
+
+  while (days > (days_in_year = DaysInYear (year)))
+    {
+      days -= days_in_year;
+      year += 1;
+    }
+
+  printf ("day #%d in the year %d\n", days, year);
+  return 0;
+}
-- 
GitLab