diff --git a/20151126/aufgabe-2.c b/20151126/aufgabe-2.c new file mode 100644 index 0000000000000000000000000000000000000000..896d26abb436db6eb4ed3ffa634c94907accefb8 --- /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 0000000000000000000000000000000000000000..bfc5bd28d982a8ac52cce849ecc5e7421ea291d4 --- /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 0000000000000000000000000000000000000000..d061c6467750cd7fcab9b1f509434c7c3094b89a --- /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 0000000000000000000000000000000000000000..d3af87c5e106b3b068c063c9bedc8f4c6377c33d --- /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 0000000000000000000000000000000000000000..5a0e6e40ea48bd03b295abe83188b3abb934ba28 --- /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; +}