QQ网名大全

电子万年历:用c语言设计一个年历系统,功能要求: (1)输入任一年将显示出该年的所有月份日期,对应的星

两个月并排显示也太变态了,这个是各个月连续显示的。

#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <time.h>

int leap(int year )
{
if ((year %4 == 0) && (year % 100 != 0)
|| (year % 400 == 0))
{
return 1;
}
return 0;
}

void show(int year,int month)
{
const char month_str[][4]={"","jan","feb","mar","apl",
"may","jun","jul","aug","sep","oct","nov","dec"};
const int month_day[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int i,j,wdays,mdays,days;
int count=0;

for(i=1,days=0;i<year;i++)
{
if(leap(i))
{
days += 366;
}
else
{
days += 365;
}
}
for(i=1;i<month;i++)
{
if(i==2 && leap(year))
{
days+=29;
}
else
{
days+=month_day[i];
}
}

printf("\n----------------------------\n");
printf(" %s %d\n",month_str[month],month);
printf(" sun mon tue wed thu fri sat\n");

wdays = days % 7;
for( j = 0; j <= wdays; j++)
{
if(wdays==6) break;

for( i = 0; i < 4; i++)
{
printf(" ");
}
count++;
}
if(month == 2 && leap(year))
{
mdays=29;
}
else
{
mdays= month_day[month];
}
for(i=1;i<=mdays;i++)
{
if( i > 1 && count % 7 == 0 )
{
printf("\n");
}
printf("%4d",i);
count++;
}
printf("\n----------------------------\n");
}

main()
{
int year,month;

printf("input the year:");
scanf("%d",&year);

printf("the calendar of the year %d.",year);
printf("\n----------------------------\n");
for(month=1;month<=12;month++)
show(year,month);

system("pause");
}
佚名
2024-05-29 11:35:27
最佳回答
类似问题(10)