打印日历c语言函数 C语言打印月历

用C语言编写一个日历

# include stdio.h

创新互联公司主要从事网页设计、PC网站建设(电脑版网站建设)、wap网站建设(手机版网站建设)、响应式网站、程序开发、网站优化、微网站、微信小程序定制开发等,凭借多年来在互联网的打拼,我们在互联网网站建设行业积累了丰富的成都做网站、成都网站建设、网站设计、网络营销经验,集策划、开发、设计、营销、管理等多方位专业化运作于一体。

# include math.h

void printmonth(int m);

void printhead(int m);

int daysofmonth(int m);

int firstday(int y);

int year,weekday;

void main()

{

int i;

printf("请输入年份:");

scanf("%d", year);

weekday=firstday(year);

printf("\n\n");

printf(" %d年\n",year);

for(i=1;i=12;i++)

{

printmonth(i);

printf("\n");

}

printf("\n\n");

}

void printmonth(int m) //打印每月日历

{

int i,days;

printhead(m);

days=daysofmonth(m);

for(i=1;i=days;i++)

{

printf("%5d",i);

weekday=(weekday+1)%7;

if (weekday==0) printf("\n ");

}

}

void printhead(int m) //打印每月的日历头(判定起始位置)

{

int i;

printf("\n%d月 日 一 二 三 四 五 六\n",m);

printf(" ");

for(i=0;iweekday;i++)

printf(" ");

}

int daysofmonth(int m) //每月的天数

{

switch (m)

{

case 1:

case 3:

case 5:

case 7:

case 8:

case 10:

case 12:return 31;

case 4:

case 6:

case 9:

case 11:return 30;

case 2:if (((year%4==0 year%100!=0)||year%400==0))

return 29;

else

return 28;

default: return 0;

}

}

int firstday(int y) //判断某年元旦是星期几

{

double s ;

s=floor(year-1+(year-1)/4.0-(year-1)/100.0+(year-1)/400.0+1);

return (int)s%7;

}

利用c语言输出某月日历

#include stdio.h

#include string.h

bool isLeapYear(int);

int getWeekDay(int, int, int);

int main(int argc, char const *argv[])

{

int year;

int month;

printf("输入日期(yyyy-mm):");

scanf("%d-%d-%d", year, month);//输入年和月

printf(" %d年%d月\n", year, month);//输出日历日历标题

printf("日 一 二 三 四 五 六\n");//输出星期

//本函数获取某个日期是星期几,这里获取每月的1号是星期几,返回是是[0-7]对应(星期天-星期六)

int week = getWeekDay(year, month, 1);

int i;

for (i = 0; i week; i++)//每月第一周前几天用空格填充

printf(" ");

int endDayOfMonth;//每个月的最后一天

if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)

endDayOfMonth = 31;

else if (month == 2)

{

if (isLeapYear(year))

endDayOfMonth = 29;

else

endDayOfMonth = 28;

}

else

endDayOfMonth = 30;

int dayOfMonth = 1;

//从一号循环到本月末

while (dayOfMonth = endDayOfMonth)

{

printf("%2d ", dayOfMonth);

dayOfMonth++;

//每输出完星期六的日期后就换行(对应周数起点是从week开始的,所以要在天数上加上week)

if ((dayOfMonth + week- 1) % 7 == 0)

printf("\n");

}

printf("\n");

return 0;

}

//判断闰年

bool isLeapYear(int y)

{

if (y % 4 == 0 y % 100 != 0 || y % 400 == 0)

return true;

return false;

}

//获取某天是星期几返回值(0-7)

int getWeekDay(int y, int m, int d)

{

//计算星期几的固定公式,Y是年D是这个日期在本年的天数

//W = [Y-1] + [(Y-1)/4] - [(Y-1)/100] + [(Y-1)/400] + D

int days = d;

int i;

for (i = 1; i m; i++)

{

if (i == 1 || i == 3 || i == 5 || i == 7 || i == 8 || i == 10 || i == 12)

days += 31;

else if (i == 2)

{

if (isLeapYear(y))

days += 29;

else

days += 28;

}

else

days += 30;

}

int temp = y - 1 + (int)((y - 1) / 4) - (int)((y - 1) / 100) + (int)((y - 1) / 400) + days;

return temp % 7;

}

c语言打印月历 怎么编写啊~ 谢谢!

我这儿有一个万年历的程序,楼主可以试着编写实现你所需要的功能。希望有所帮助。

#includestdio.h

#includestdlib.h

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

int n[13]={0,31,29,31,30,31,30,31,31,30,31,30,31};

char w[7][3]={"日","一","二","三","四","五","六"};

char mon[13][7]={"","一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"};

/*判断是否为闰年*/

int IsLeap(int year)

{

if((year%4==0 year%100!=0)||(year%400==0))

return 1;

else

return 0;

}

/*计算某年某月某日是星期几*/

int Getweekday(int year,int month,int day)

{

int weekday;

int dayCount=0;

int i;

if(IsLeap(year))

{

for(i=1;imonth;i++)

dayCount+=n[i];

}

else

{

for(i=1;imonth;i++)

dayCount+=m[i];

}

dayCount=dayCount+day;

weekday=((year-1)+(year-1)/4-(year-1)/100+(year-1)/400+dayCount)%7;

return weekday;

}

/*判断某年某月某日是星期几的函数*/

void SelectDay()

{

int year,month,day;

char ch;

int weekday;

printf("请输入年月日(xxxx-xx-xx):\t");

scanf("%d-%d-%d",year,month,day);

weekday=Getweekday(year,month,day);

printf("\n");

printf("%d年%d月%d日是:星期%s\n",year,month,day,w[weekday]);

printf("\n您还需要继续查询吗?\t是(Y)/否(N)");

getchar();

ch=getchar();

if(ch=='y'||ch=='Y')

SelectDay();

}

/*输出某月的日历*/

void GetMonth(int year,int month )

{

int weekday,i,monthday;

weekday=Getweekday(year,month,1);

printf("日\t一\t二\t三\t四\t五\t六\n");

for(i=0;iweekday;i++)

printf("\t");

if(IsLeap(year))

monthday=n[month];

else

monthday=m[month];

for(i=1;i=monthday;i++)

{

printf("%2d\t",i);

weekday++;

if(weekday%7==0)

printf("\n");

}

printf("\n");

}

/*打印某年某月日历函数*/

void Month()

{

int year,month;

char ch;

printf("请输入年月(xxxx-xx):\t");

scanf("%d-%d",year,month);

printf("\n");

GetMonth(year,month );

printf("\n您还需要继续查询吗?\t是(Y)/否(N)");

getchar();

ch=getchar();

if(ch=='y'||ch=='Y')

Month();

}

/*打印某年日历函数*/

void Year()

{

int year,i;

char ch;

printf("请输入年份:\n");

scanf("%d",year);

for(i=1;i=12;i++)

{

printf("%s\n",mon[i]);

GetMonth(year,i);

printf("\n\n");

}

printf("\n您还需要继续查询吗?\t是(Y)/否(N)");

getchar();

ch=getchar();

if(ch=='y'||ch=='Y')

Year();

}

/*退出程序*/

void Exit()

{

char ch;

getchar();

printf("是否确定退出?\t是(Y)/否(N)");

ch=getchar();

if(ch=='y'||ch=='Y')

printf("感谢您的使用!!\n\n");

exit(0);

}

/*主函数*/

void main()

{

int choice;

while(1)

{

printf("欢迎使用该系统!!\n");

printf("**===**===**===**===**===**===**===**===**===**\n");

printf("1.查询某年某月某日是星期几\n");

printf("2.打印某年某月的全月日历\n");

printf("3.打印某年的全年日历\n");

printf("4.退出系统\n");

printf("**===**===**===**===**===**===**===**===**===**\n");

printf("请输入您需要进行的操作前面的序号: ");

scanf("%d",choice);

switch(choice)

{

case 1:SelectDay(); break;

case 2:Month(); break;

case 3:Year(); break;

case 4:Exit(); break;

}

}

}

c语言打印日历,大神帮我看看代码。。。,

改3个地方就可以了。

1.把PrintMonthCalender()中的

for(;i=m;i++)

{

startDay++;

printf("\t%d",i);

if(startDay==6)

printf("\n");

}

改成

for(;i=m;i++){

if(startDay++==6){

printf("\n");

startDay=0;

}

printf("\t%d",i);

}

2.把GetMonthDays()中的

case 2:

if(c==1)

return 29 ;break;

if(c==0)

return 28 ;break;

改成

case 2:

if(c==1) return 29;

else return 28;

3. 把GetWeekDay()中的

case 2: result+=30;

改成

case 2: result+=28;

并把

if (c==1)

result++;

改成if(c==1 month2) result++;

再把凡是紧跟在return后面的break删除;在system("pause")前加一句printf("\n")就OK了……

C语言编写日历

#include stdio.h

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

void print_calendar(int y);

void main()

{

int y;

printf("Calendar system :\n");

printf("Please input a year between 1600 2500:");

while(scanf("%d",y)!=EOF)//输入年份

{

if (y1600 || y2500)

{

printf("Invalid input. Please try again!\n");

printf("Please input a year between 1600 2500:");

continue;

}

print_calendar(y);

}

}

void print_calendar(int y) //打印日历

{

int i,sum,days,k,m;

char monthname[12][20] = {"January","February","March","April","May","June","July","August","September","October","November","December"};

if((0==y%4y%100!=0)||0==y%400 ) //闰年判断

month[2]=29;

for(m=1;m13;m++)

{

days = 0;

for (i=1;im;i++) //计算m月1号是第几天

days+=month[i];

days++;

sum=y-1+(y-1)/4-(y-1)/100+(y-1)/400+days;

k=sum%7; //k是星期几,k=0星期日

printf("%s %d\n",monthname[m-1],y);

printf(" S M Tu W Th F S\n");

printf("%*d",3*(k+1)-1,1);//先输出3*(k+1)-1个空格,在输出1

k++;

for(i=2;i=month[m];i++)

{

if(k == 7)

{

printf("\n");

k=0;

}

if (k == 0)

printf("%2d",i);

else

printf("%3d",i);

k++;

}

printf("\n\n");

}

}

C语言“打印日历”的程序是什么?

#include stdio.h

void main()

{

int i,j,k,year,week;

int day[]={31,28,31,30,31,30,31,31,30,31,30,31};

char month[12][10]={"January","February","March","April","May","June","July","August","September","October","November","December"};

printf("Input year you want to print:");

scanf("%d",year);

if((year%4==0year%100!=0)||(year%400==0)) day[1]++; //判断是否闰年

week=(35+year+year/4-year/100+year/400)%7; //计算当年的1月1日是周几的公式

for(i=0;i12;i++)

{

printf("\n%s\n",month[i]); //输出月份的英文

printf("Sun Mon Tue Wed Thu Fri Sat\n"); //输出表头

for(k=0;kweek;k++) printf(" "); //每月一号对齐它的星期数

for(j=1;j=day[i];j++)

{

printf("%3d ",j);

if(++week=7)

{

printf("\n");

week=week%7;

}

}

printf("\n");

}

}


网页标题:打印日历c语言函数 C语言打印月历
网页URL:http://pwwzsj.com/article/doohshs.html