This commit is contained in:
Kyryl Kobzar 2019-03-14 22:05:33 +01:00
parent 5681a7d1cc
commit b7a6d05399
2 changed files with 30 additions and 11 deletions

BIN
program

Binary file not shown.

View File

@ -3,14 +3,33 @@
int main() int main()
{ {
/* initialize */ int d = 0;
int y=0, m=0, d=0; int m = 0;
fgets("%d.%d.%d", &d, &m, &y); int y = 0;
struct tm t = { .tm_year=y-1900, .tm_mon=m-1, .tm_mday=d }; scanf("%d.%d.%d", &d, &m, &y);
/* modify */
t.tm_mday += 40; //check date validness
mktime(&t); if(!(m>=1 && m<=12) && !(y>=0 && y<=9999) && !(((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==29 && m==2 && (y%400==0 ||(y%4==0 && y%100!=0))) || ((d>=1 && d<=28) && m==2))){
/* show result */ puts("Nespravny datum\n");
printf("%s", asctime(&t)); /* prints: Sun Mar 16 00:00:00 1980 */
return 0; 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
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 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{
printf("%d.%d.%d\n\n", t.tm_mday, t.tm_mon+1, t.tm_year+1900);
}
} }