pvjc20/du3/program.c

66 lines
954 B
C

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
char *str;
str = (char*) malloc(12);
scanf("%s",str);
int day=0;
int m=0;
int y=0;
int z=0;
sscanf(str, "%d.%d.%d", &day, &m, &y);
if(y%400==0 ||(y%100!=0 && y%4==0)){
z++;
}
if(m==2){
if(z==1 &&day>29){
printf("Nespravny datum\n");
return 0;
}
if(z==0 &&day>28){
printf("Nespravny datum\n");
return 0;
}
}
day+=7;
if(m%2!=0 && day>31){
day-=31;
m++;
}
if(m%2==0 && day>30){
if(m==2 &&(y%400==0 ||(y%100!=0 && y%4==0))){
day-=29;
}
else if(m==2){
day-=28;
}
else{
day-=30;
}
m++;
}
if(m>12){
m-=12;
day--;
y++;
}
if(m>9 && day>9){
printf("%d.%d.%d\n",day,m,y);
}
else if(m<10 && day>9){
printf("%d.0%d.%d\n",day,m,y);
}
else if(m>9 && day<10){
printf(" %d.%d.%d\n",day,m,y);
}
else{
printf(" %d.0%d.%d\n",day,m,y);
}
printf("\n");
return 0;
}