#include <stdio.h>
int day_of_year(int year, int month, int day, int leap);
void month_day(int year, int yearday, int leap);
static char daytab[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 main(int argc, char *argv[])
{
int c, leap, y, m, d, yearday;
// c - correct flag
// leap - leap year flag
// y - year, m - month, d - day
input:
scanf("%d %d %d", &y, &m, &d);
c = 0;
if(y < 0){
printf("Year couldn't be negative\n");
c = 1;
}
if(m <= 0 || m >= 12){
printf("Month got to be 1-12\n");
c = 1;
}
leap = y%4 == 0 && y%100 != 0 || y%400 == 0;
if(d > daytab[leap][m] || d <= 0){
printf("Day got to be more than 0 and not exceed days per month maximum\n");
c = 1;
}
if(c == 1)
goto input;
yearday = day_of_year(y, m, d, leap);
month_day(y, yearday, leap);
return 0;
}
int day_of_year(int year, int month, int day, int leap){
int i;
printf("%d.", day);
for(i = 1; i < month; i++)
day += daytab[leap][i];
printf("%d is the %d's day of %d year\n", month, day, year);
return day;
}
void month_day(int year, int yearday, int leap){
int i, m, d;
for(i = 1; yearday > daytab[leap][i]; i++)
yearday -= daytab[leap][i];
m = i;
d = yearday;
printf("Full date: %d/%d/%d\n", m, d, year);
}
Розберіть та редагуйте цей код.