Aktualizovat "program.c

This commit is contained in:
Kristián Ruják 2019-03-13 22:34:52 +00:00
parent 3477d0d858
commit 1349382497

144
program.c
View File

@ -7,46 +7,186 @@ int main()
scanf("%d.%d.%d", &d, &m, &y); scanf("%d.%d.%d", &d, &m, &y);
if(y>=0 && y<=9999) if(y>=0 && y<=9999)
{ {
//check month
if(m>=1 && m<=12) if(m>=1 && m<=12)
{ {
//check days
if((d>=1 && d<=31) && (m==1 || m==3 || m==5 || m==7 || m==8 || m==10 || m==12)) if((d>=1 && d<=31) && (m==1 || m==3 || m==5 || m==7 || m==8 || m==10 || m==12))
{} {}
else if((d>=1 && d<=30) && m==4 || m==6 || m==9 || m==11) else if((d>=1 && d<=30) && m==4 || m==6 || m==9 || m==11)
{} {}
else if((d>=1 && d<=28) && m==2) else if((d>=1 && d<=28) && m==2)
{} {}
else if(d==29 && m==2 && (y%400==0 ||(y%4==0 && y%100!=0))) else if(d==29 && m==2 && (y%400==0 ||(y%4==0 && y%100!=0)))
{} {}
else{ else{
printf("Nespravny datum\n"); printf("Nespravny datum\n");
return 0; return 0;
} }
} }
else else
{ {
printf("Nespravny datum\n"); printf("Nespravny datum\n");
return 0; return 0;
} }
} }
else else
{ {
printf("Nespravny datum\n"); printf("Nespravny datum\n");
return 0; return 0;
} }
struct tm t = { .tm_year=y-1900, .tm_mon=m-1, .tm_mday=d }; struct tm t = { .tm_year=y-1900, .tm_mon=m-1, .tm_mday=d };
t.tm_mday += 7; t.tm_mday += 7;
mktime(&t); mktime(&t);
if(t.tm_mday <10 && t.tm_mon+1 < 10){ if(t.tm_mday <10 && t.tm_mon+1 < 10){
printf(" %d.0%d.%d\n\n", t.tm_mday, t.tm_mon+1, t.tm_year+1900); printf(" %d.0%d.%d\n\n", t.tm_mday, t.tm_mon+1, t.tm_year+1900);
} }
else if(t.tm_mday < 10){ else if(t.tm_mday < 10){
printf(" %d.%d.%d\n\n", t.tm_mday, t.tm_mon+1, t.tm_year+1900); printf(" %d.%d.%d\n\n", t.tm_mday, t.tm_mon+1, t.tm_year+1900);
} }
else if(t.tm_mon+1 < 10){ else if(t.tm_mon+1 < 10){
printf("%d.0%d.%d\n\n", t.tm_mday, t.tm_mon+1, t.tm_year+1900); printf("%d.0%d.%d\n\n", t.tm_mday, t.tm_mon+1, t.tm_year+1900);
} }
else{ else{
printf("%d.%d.%d\n\n", t.tm_mday, t.tm_mon+1, t.tm_year+1900); printf("%d.%d.%d\n\n", t.tm_mday, t.tm_mon+1, t.tm_year+1900);
} }