c 语言编程:黑色星期五

来源:百度知道 编辑:UC知道 时间:2024/06/22 19:34:17
求编程
输入年份,判断该年是否包含黑色星期五,如包含,给出具体日期
例如 输入2006
输出
There are 2 Black Fridays in year 2006.
They are:
2006/1/13
2006/10/13
黑色星期五:即是13号又是星期五

代码:

#include <stdio.h>

int iMonthDays[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int iAddMonthDays[13];

int IsLeapYear(long iYear);
int GetWeekDay(long iNowDate);

main()
{
long theyear;
long thedate;
int i;
int count = 0;

iAddMonthDays[0] = 0;
for (i = 1; i < 13; i++)
{
iAddMonthDays[i] = iAddMonthDays[i - 1] + iMonthDays[i];
}

printf("Input the year: ");
scanf("%ld", &theyear);

for (i = 1; i < 13; i++)
{
thedate = theyear * 10000 + i * 100 + 13;
if (GetWeekDay(thedate) == 5)
{
printf(((i < 10) ? "%ld/0%d/13\n" : "%ld/%2d/13\n"), theyear, i);
count++;
}
}

if (count == 0)
printf("\nThere is no Black Friday in year %ld.\n", theyear);
else
printf("\nTh