思路:
為衡陽等地區(qū)用戶提供了全套網(wǎng)頁設(shè)計制作服務(wù),及衡陽網(wǎng)站建設(shè)行業(yè)解決方案。主營業(yè)務(wù)為網(wǎng)站建設(shè)、做網(wǎng)站、衡陽網(wǎng)站設(shè)計,以傳統(tǒng)方式定制建設(shè)網(wǎng)站,并提供域名空間備案等一條龍服務(wù),秉承以專業(yè)、用心的態(tài)度為用戶提供真誠的服務(wù)。我們深信只要達到每一位用戶的要求,就會得到認可,從而選擇與我們長期合作。這樣,我們也可以走得更遠!1. 編寫函數(shù)判斷平年閏年
2. 編寫函數(shù)獲得某年某月的天數(shù)
3. 編寫函數(shù)判斷這一年距離公元1年相差多少天
4. 編寫函數(shù)判斷某年某月距離公元1年1月相差多少天
5. 編寫函數(shù)打印某一年12個月份的日歷
6. 編寫函數(shù)打印某年某月的月歷
7. 編寫函數(shù)查詢某個日期為星期幾,什么節(jié)日
運行圖:
源代碼:
#include#includestatic char week[7][7] = {"周一", "周二", "周三", "周四", "周五", "周六", "周日"};
static char month[12][10] = {"一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"};
int IsLeapYear(int year)
{
if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0))
return 1;
return 0;
}
int GetMonDays(int year, int mon)
{
int days[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
if (mon == 2 && (IsLeapYear(year) == 1))
{
return 29;
}
return days[mon];
}
long DaysY(int year)
{
long sum = 0;
int i;
for (i = 1; i< year; i++)
{
if (IsLeapYear(i) == 1)
sum += 366;
else
sum += 365;
}
return sum;
}
long DaysM(int year, int mon)
{
long sum = DaysY(year);
int i;
for (i = 1; i< mon; i++)
{
sum += GetMonDays(year, i);
}
return sum;
}
void ShowM(int year, int mon)
{
long sum = DaysM(year, mon);
int ret = sum % 7;
int temp = 7 - ret;
int i;
printf("\n %6s\n", month[mon - 1]);
printf("--------------------------------------------------\n");
for (i = 0; i< 7; i++)
{
printf("| %5s ", week[i]);
}
printf("|\n");
for (i = 0; i< 7; i++)
{
printf("|------");
}
printf("|\n");
for (i = 0; i< ret; i++)
{
printf("| ");
}
for (i = 1; i<= GetMonDays(year, mon); i++)
{
printf("|%4d ", i);
if (i == temp || (i - temp) % 7 == 0)
{
printf("|\n");
int j;
for (j = 0; j< 7; j++)
{
printf("|------");
}
printf("|\n");
}
}
if ((ret + GetMonDays(year, mon)) % 7 != 0)
{
printf("|\n");
}
ret = ((GetMonDays(year, mon)) % 7 + ret) % 7;
for (i = 0; i< ret; i++)
{
printf("|------");
}
if (ret != 0)
{
printf("|\n");
}
}
void ShowY(int year)
{
printf(" 萬年歷??%d年\n",year);
printf(" ***********************************************\n");
int i;
for (i = 0; i< 12; i++)
{
ShowM(year, i + 1);
printf("\n");
}
}
void menu()
{
printf(" ***********************************************\n");
printf(" ****************** 1.查詢某年 *************\n");
printf(" ****************** 2.查詢某年某月 *************\n");
printf(" ****************** 3.查詢年月日 *************\n");
printf(" ****************** 0.退出查詢 *************\n");
printf(" ***********************************************\n");
}
int main()
{
int input;
int year, mon, day;
do
{
menu();
printf("\n請選擇:>");
scanf("%d", &input);
system("clear");
switch (input)
{
case 1:
printf("請輸入需要查詢的年份:>");
while (~scanf("%d", &year))
{
if (year >= 1)
{
system("clear");
ShowY(year);
printf("請輸入需要查詢的年份:>");
}
else if (year == 0)
{
printf("退出年份查詢\n\n");
break;
}
else
{
printf("查詢超出范圍,請重新輸入:>");
}
}
break;
case 2:
printf("請輸入需要查詢的年月:>");
while(~scanf("%4d%2d", &year, &mon))
{
if (year >= 1)
{
ShowM(year, mon);
printf("\n請輸入需要查詢的年月:>");
}
else if (year == 0 || mon == 0)
{
printf("退出年月查詢\n\n");
break;
}
else
{
printf("查詢超出范圍");
}
}
break;
case 3:
printf("請輸入需要查詢的日期:>");
while(~scanf("%4d%2d%2d", &year, &mon, &day))
{
if (year >= 1 && mon<= 12 && day<= GetMonDays(year, mon))
{
long sum = DaysM(year, mon) + day;
int ret = sum % 7;
if (ret == 0)
ret = 7;
printf("%7s\n", week[ret - 1]);
if (mon == 1 && day == 1)
printf("元旦節(jié)");
else if (mon == 2 && day == 14)
printf("情人節(jié)");
else if (mon == 3 && day == 8)
printf("婦女節(jié)");
else if (mon == 4 && day == 1)
printf("愚人節(jié)");
else if (mon == 5 && day == 1)
printf("勞動節(jié)");
else if (mon == 6 && day == 1)
printf("兒童節(jié)");
else if (mon == 7 && day == 1)
printf("建黨節(jié)");
else if (mon == 8 && day == 1)
printf("建軍節(jié)");
else if (mon == 10 && day == 1)
printf("國慶節(jié)");
else if (mon == 10 && day == 31)
printf("萬圣夜");
else if (mon == 11 && day == 24)
printf("感恩節(jié)");
else if (mon == 12 && day == 25)
printf("圣誕節(jié)");
printf("\n\n");
printf("請輸入需要查詢的日期: >");
}
else if (year == 0 || mon == 0 || day == 0)
{
printf("退出日期查詢\n\n");
break;
}
else
printf("超出查詢范圍,請重新輸入:>");
}
case 0:
break;
default:
printf("輸入錯誤,請重新選擇:>");
break;
}
} while (input);
return 0;
}
你是否還在尋找穩(wěn)定的海外服務(wù)器提供商?創(chuàng)新互聯(lián)www.cdcxhl.cn海外機房具備T級流量清洗系統(tǒng)配攻擊溯源,準(zhǔn)確流量調(diào)度確保服務(wù)器高可用性,企業(yè)級服務(wù)器適合批量采購,新人活動首月15元起,快前往官網(wǎng)查看詳情吧