#include<stdio.h>
#include<time.h>
main(){
//定义变量
struct tm t,*date;
time_t t_day;
int year,month;
int month_day;
int i,j;
struct tm *local;
time_t t_mow;
t_mow=time(NULL);
local=gmtime(&t_mow);
//输入年份和月份
printf("请输入年份:\n");
scanf("%d",&year);
printf("请输入月份:\n");
scanf("%d",&month );
if(month==2 ){
if(year%4==0 && year%100!=0)
month_day=29;
else
month_day=28;
}
else if(month==1||month==3||month==5||month==7||month==8||month==10||month==12)
{
month_day=31;
}
else
month_day=30;
printf("当前时间是: ");
printf(asctime(local));
printf("\n\n");
printf("当月天数是:%d \n\n 日历\n",month_day); //输出当前天数
printf("一\t二\t三\t四\t五\t六\t日\t\n"); //日历的第一行,显示一二三四五六日
for (i=1;i<=month_day;i++)
{
t.tm_year=year-1900;
t.tm_mon=month-1;
t.tm_mday=i;
t.tm_hour=0;
t.tm_min=0;
t.tm_sec=0;
t.tm_isdst=0;
t_day=mktime(&t);
date=gmtime(&t_day);
if(i==1)
{
for(j=0;j<date->tm_wday;j++)
printf("\t");
}
if(date->tm_wday==6)
{
printf("%d\n",i);
}
else
printf("%d\t",i);
}
printf("\n\n",i);
}
温馨提示:答案为网友推荐,仅供参考