25.5.3
This commit is contained in:
parent
f7b7880a24
commit
5b29863cc5
75
jahrtag.c
Normal file
75
jahrtag.c
Normal file
@ -0,0 +1,75 @@
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
int monat_tage[2][13] = {
|
||||
{0, 31, 28, 31, 30, 31, 30, 31, 31,30,31,30,31},
|
||||
{0, 31, 29, 31, 30, 31, 30, 31, 31, 30,31,30,31}};
|
||||
|
||||
|
||||
int schaltjahr(int jahr){
|
||||
return(jahr % 4 == 0 && jahr % 100 != 0) || (jahr % 400 == 0);
|
||||
|
||||
}
|
||||
|
||||
int datum_zu_tagesnummer(int monat,int jahr)
|
||||
{
|
||||
|
||||
int anzahlTage = 0;
|
||||
int schalt = schaltjahr(jahr);
|
||||
|
||||
for (int i = 1; i < monat ; ++i) {
|
||||
anzahlTage += monat_tage[schalt][i];
|
||||
}
|
||||
|
||||
return anzahlTage;
|
||||
}
|
||||
|
||||
void tagesnummer_zu_datum(int taganzahl, int jahr, int *tag, int *monat) {
|
||||
int i;
|
||||
int schalt = schaltjahr(jahr);
|
||||
|
||||
for (i = 1; i <= 12 && taganzahl > monat_tage[schalt][i]; i++) {
|
||||
taganzahl -= monat_tage[schalt][i];
|
||||
}
|
||||
*monat = i;
|
||||
*tag = taganzahl;
|
||||
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
int eingabe;
|
||||
|
||||
do{
|
||||
int tag, monat, jahr,taganzahl;
|
||||
int c;
|
||||
printf("0 Ende\n");
|
||||
printf("1 Datum zu einer Tagesnummer bestimmen\n");
|
||||
printf("2 Tagesnummer zu einem Datum bestimmen\n");
|
||||
printf("\nDeine Wahl: ");
|
||||
scanf("%d", &eingabe);
|
||||
|
||||
|
||||
switch (eingabe) {
|
||||
case 1:
|
||||
printf("\nGib dein Datum (tt.mm.jjjj) ein: ");
|
||||
scanf("%d.%d.%d", &tag, &monat, &jahr);
|
||||
printf(".... %02d.%02d.%d = %d. Tag im Jahr\n\n", tag, monat, jahr, datum_zu_tagesnummer(monat,jahr)+tag);
|
||||
break;
|
||||
case 2:
|
||||
printf("\nGib Tagesnummer und Jahr (nr,jahr) ein: ");
|
||||
scanf("%d,%d", &taganzahl, &jahr);
|
||||
tagesnummer_zu_datum(taganzahl, jahr, &tag, &monat);
|
||||
printf(".... %d. Tag im Jahr = %02d.%02d.%d\n\n", taganzahl, tag, monat, jahr);
|
||||
break;
|
||||
case 0:
|
||||
break;
|
||||
default:
|
||||
printf("Keine richtige Eingabe!\n");
|
||||
while ((c = getchar()) != '\n' && c != EOF) { }
|
||||
eingabe = 3;
|
||||
break;
|
||||
}
|
||||
|
||||
}while(eingabe!=0);
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user