?
#include <stdio.h>
#include <stdlib.h>
struct Datum
{
int t; //Tag
int m; //Monat
int j; //Jahr
};
int Schaltjahr(int j)
{
return j%4==0&&j%100||j%400==0;
}
Datum* Datumsausgabe(int Tagesnummer, int Jahr)
{
int i;
static struct Datum Date;
int temp[] = {31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365};
int tmp[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
tmp[1] = Schaltjahr(Jahr) ? 29 : 28;
for (i = 1; i < 12; i++)
if (Schaltjahr(Jahr))
temp[i]++;
for (i = 0; i < 12; i++)
{
if ((temp[i]-Tagesnummer) >= 0)
{
Date.m = i+1;
Date.t = tmp[i]-(temp[i]-Tagesnummer);
Date.j = Jahr;
break;
} // Gregorjanischer Kalender von 1583 bis 2399
}
if (Date.m>=1&&Date.m<=12&&Date.j>=1583&&Date.j<=2399/*oder mehr*/
&&Date.t>=1&&Date.t<=tmp[Date.m-1]&&i<12) // Plausibilitätsprüfung
return &Date;
else
{
printf("Fehler! Keine Datumsausgabe moeglich.\n");
return NULL;
}
}
int main()
{
Datum* x = Datumsausgabe(70,2008);
if (x)
printf("Tag: %d\nMonat: %d\nJahr: %d\n", x->t, x->m, x->j);
return EXIT_SUCCESS;
}