This commit is contained in:
2025-04-21 00:40:30 +02:00
parent 9ccc21edde
commit b8c75fc6d3
87 changed files with 2788 additions and 99 deletions

38
S1/GdCP/day.c Normal file
View File

@@ -0,0 +1,38 @@
#include<stdio.h>
// Lists to define the calendar
char *day[7] = {"Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag", "Sonntag"};
int months[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int leap = 29;
// Check for leap year
int isleap(int y) {
return ((y % 4 == 0 && y % 100 != 0) || y % 400 == 0);
}
int main() {
// Stating date for the 1.1.1600 is a Saturday
int n = 5;
// Read in the date
int d, m, y;
scanf("%d.%d.%d", &d, &m, &y);
// Check for errors
if (d < 1 || m < 1 || m > 12 || d > months[m-1] || y < 1600 || y > 4000) return 1;
// Get the number of days passed
for (int i = 1600; i < y; i++) {
if (isleap(i)) n+= 366;
else n += 365;
}
for (int i = 0; i < m - 1; i++) {
if (isleap(y)) {
if (i == 1) n += leap;
else n += months[i];
} else n += months[i];
}
n += d - 1;
// Print the day
printf("%s\n", day[n % 7]);
}