Calendar.h ¶
#include <stdio.h>
void printCalender(int year, int first);
void printFirstTab(int month, int year);
int printDays(int month, int year, int leftDays);
void print_space();
void print_days(int day);
int daysOfMonth(int month, int year);
int IsLeafYear(int year);
void printFirstTab(int month, int year);
int printDays(int month, int year, int leftDays);
void print_space();
void print_days(int day);
int daysOfMonth(int month, int year);
int IsLeafYear(int year);
void printCalender(int year, int first)
{
{
int month, leftDays;
for(month = 1 ; month <= 12 ; month++)
{
}for(month = 1 ; month <= 12 ; month++)
{
printFirstTab(month, year);
leftDays = printDays(month, year, first);
first = leftDays;
}leftDays = printDays(month, year, first);
first = leftDays;
void printFirstTab(int month, int year)
{
{
switch(month)
{
printf("---------------------------------------------------\n");
printf("Mon Tue Wed Thu Fri Sat Sun\n");
}{
case 1:
}printf(" January %d \n", year);
break;
case 2:break;
printf(" February %d \n", year);
break;
case 3:break;
printf(" March %d \n", year);
break;
case 4:break;
printf(" April %d \n", year);
break;
case 5:break;
printf(" May %d \n", year);
break;
case 6:break;
printf(" June %d \n", year);
break;
case 7:break;
printf(" July %d \n", year);
break;
case 8:break;
printf(" August %d \n", year);
break;
case 9:break;
printf(" September %d \n", year);
break;
case 10:break;
printf(" October %d \n", year);
break;
case 11:break;
printf(" November %d \n", year);
break;
case 12:break;
printf(" December %d \n", year);
break;
break;
printf("---------------------------------------------------\n");
printf("Mon Tue Wed Thu Fri Sat Sun\n");
int printDays(int month, int year, int leftDays)
{
{
int cnt = 0;
int day = daysOfMonth(month, year);
for(int i = 1 ; i <= leftDays ; i++)
{
for(int nowday = 1 ; nowday <= day ; nowday++) //print day from 1 to day
{
printf("\n\n");
return cnt;
}int day = daysOfMonth(month, year);
for(int i = 1 ; i <= leftDays ; i++)
{
print_space(); //print space leftDays times
cnt++;
}cnt++;
for(int nowday = 1 ; nowday <= day ; nowday++) //print day from 1 to day
{
if(cnt == 7){
print_days(nowday);
cnt++;
}printf("\n");
cnt = 0;
}cnt = 0;
print_days(nowday);
cnt++;
printf("\n\n");
return cnt;
void print_space()
{
{
printf("\t");
}void print_days(int day)
{
{
printf("%d\t", day);
}int daysOfMonth(int month, int year)
{
{
int days;
switch(month)
{
return days;
}switch(month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
case 4:
case 6:
case 9:
case 11:
}case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
days = 31;
break;
break;
case 4:
case 6:
case 9:
case 11:
days = 30;
break;
case 2:break;
return days;
int IsLeafYear(int year)
{
{
if(year%4 == 0)
}return 0; //True
if(year%100 == 0)
elseif(year%100 == 0)
return 1; //False
if(year%400 == 0)
if(year%400 == 0)
return 0; //True
return 1; //False