pvjc19cv4/program.c

34 lines
1.1 KiB
C
Raw Normal View History

2019-03-06 07:02:47 +00:00
#include <stdio.h>
2019-03-06 07:22:47 +00:00
#include <time.h>
2019-03-06 07:02:47 +00:00
2019-03-12 20:10:21 +00:00
int main()
2019-03-14 21:05:33 +00:00
{
int d = 0;
int m = 0;
int y = 0;
scanf("%d.%d.%d", &d, &m, &y);
//check date validness
2019-03-14 21:32:42 +00:00
if((y>=0 && y<=9999) && (m>=1 && m<=12) && (((d>=1 && d<=31) && (m==1 || m==3 || m==5 || m==7 || m==8 || m==10 || m==12)) || ((d>=1 && d<=30) && m==4 || m==6 || m==9 || m==11) || ((d>=1 && d<=28) && m==2) || (d==29 && m==2 && (y%400==0 ||(y%4==0 && y%100!=0))))){
}else{
2019-03-14 21:34:15 +00:00
puts("Nespravny datum");
2019-03-14 21:05:33 +00:00
return 0;
}
//setting date
struct tm t = { .tm_year=y-1900, .tm_mon=m-1, .tm_mday=d };
//adding week to the date
t.tm_mday += 7;
mktime(&t);
//output data
2019-03-14 21:13:58 +00:00
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);
else if(t.tm_mday < 10)
printf(" %d.%d.%d\n\n", t.tm_mday, t.tm_mon+1, t.tm_year+1900);
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);
else
2019-03-14 21:05:33 +00:00
printf("%d.%d.%d\n\n", t.tm_mday, t.tm_mon+1, t.tm_year+1900);
2019-03-06 07:02:47 +00:00
}