您好,您还记得您有编写一个输入年份输出日历的程序吗?我运行了一下,发现一直是差一天,请问是为什么啊
1个回答
展开全部
是这个吗?
#include<stdio.h>#include<windows.h>
int fun(int n)
{
if((n % 400 == 0) || (n % 4 == 0 && n % 100 != 0))
return 1;
else
return 0;
}
int main()
{
int year;
int a,i,j,k,m,n;
int s = 0, sum = 0;
int month_day[2][12] ={{31,28,31,30,31,30,31,31,30,31,30,31},
{31,29,31,30,31,30,31,31,30,31,30,31}};
printf("Please input year:");
scanf("%d",&year);
if(year == 0)
{
system("pause");
exit(0);
}
for(a = 0; a < year; a++)
{
sum += 365 + fun(a);
s = (sum -1) % 7 ;
}
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY |
FOREGROUND_GREEN);
printf("\n %d 年",year);
for(i = 0; i < 12; i++)
{
k = 1;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY |
FOREGROUND_RED);
printf("\n\n\n %d 月 \n",i+1);
printf("\n星期日 星期一 星期二 星期三 星期四 星期五 星期六\n\n");
for(n = 0; n < s; n++)
printf(" ");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY |
FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_GREEN);
for(j = 0; j < month_day[fun(year)][i]; j++)
{
printf(" %-5d",k);
if((k + s) % 7 == 0)
printf("\n");
m = (k+s) % 7;
k++;
}
s = m;
}
printf("\n");
return 0;
}
#include<stdio.h>#include<windows.h>
int fun(int n)
{
if((n % 400 == 0) || (n % 4 == 0 && n % 100 != 0))
return 1;
else
return 0;
}
int main()
{
int year;
int a,i,j,k,m,n;
int s = 0, sum = 0;
int month_day[2][12] ={{31,28,31,30,31,30,31,31,30,31,30,31},
{31,29,31,30,31,30,31,31,30,31,30,31}};
printf("Please input year:");
scanf("%d",&year);
if(year == 0)
{
system("pause");
exit(0);
}
for(a = 0; a < year; a++)
{
sum += 365 + fun(a);
s = (sum -1) % 7 ;
}
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY |
FOREGROUND_GREEN);
printf("\n %d 年",year);
for(i = 0; i < 12; i++)
{
k = 1;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY |
FOREGROUND_RED);
printf("\n\n\n %d 月 \n",i+1);
printf("\n星期日 星期一 星期二 星期三 星期四 星期五 星期六\n\n");
for(n = 0; n < s; n++)
printf(" ");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY |
FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_GREEN);
for(j = 0; j < month_day[fun(year)][i]; j++)
{
printf(" %-5d",k);
if((k + s) % 7 == 0)
printf("\n");
m = (k+s) % 7;
k++;
}
s = m;
}
printf("\n");
return 0;
}
来自:求助得到的回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询