Your question is too general. What part don't you understand?
Code:
#include <stdio.h>
#include <stdlib.h>
#ifdef _WIN32
#include <windows>
#define CLEAR_COMMAND "cls"
void gotoxy(int x, int y)
{
COORD coord = (COORD){x, y};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}
#else
#define CLEAR_COMMAND "clear"
void gotoxy(int x, int y)
{
printf("\033[%d;%dH", y + 1, x + 1);
}
#endif
int main()
{
int year, Day_of_month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
char Month[12][15] = {
"January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"};
int month, day, first_day_of_the_year;
while (1)
{
printf("Enter the year ");
scanf("%d", &year);
if (year >= 2000 && year <= 2099)
break;
printf("Year must be from 2000 to 2099\n");
}
system(CLEAR_COMMAND);
if (year % 4 == 0) // works because years are restricted to 2000 to 2099
Day_of_month[1] = 29;
first_day_of_the_year = (((year + 3 - 2000) / 4) + (year - 2000)) % 7;
for (month = 0; month < 12; month++)
{
gotoxy((3 * (month % 3) + 1) * 8 + (month % 3) * 3, 8 * (month / 3));
printf("%s", Month[month]);
gotoxy((27 * (month % 3) + 3), 8 * (month / 3) + 1);
printf("Sa Su Mo Tu We Th Fr");
for (day = 1; day <= Day_of_month[month]; day++)
{
gotoxy(27 * (month % 3) + 3 + ((first_day_of_the_year + day - 1) % 7) * 3,
2 + 8 * (month / 3) + (first_day_of_the_year + day - 1) / 7);
printf("%2d", day);
}
first_day_of_the_year = (first_day_of_the_year + Day_of_month[month]) % 7;
}
printf("\n\n");
return 0;
}
It's not a very good algorithm, anyway, since you don't really need the positioning code (gotoxy). It can be done line-by-line easily enough.