您的位置 电脑知识爱好者 >> 编程知识 >> TC2.0下怎么编写这个程序

TC2.0下怎么编写这个程序

电脑知识爱好者互联网本站整理2007-12-28 22:48:16
知识重点:#include stdio.h int m_day(int year,int month)/*此函数是给定年,月,计算此月有多少天.*/ { if ((year%4==0 case 4: case 6: case 9: case 11: return 30; case 2: return 29; } el..

#include <stdio.h> int m_day(int year,int month)/*此函数是给定年,月,计算此月有多少天.*/ { if ((year%4==0 &&year%100!=0) || (year%400==0)) switch(month) { 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: return 29; } else switch(month) { 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: return 28; } } int main() { int year,month; int i,days=0,d,day=0; printf("Enter the year and month:\n"); scanf("%d%d",&year,&month); for (i=1;i<month;i++) days+=m_day(year,i); d=year-1+(year-1)/4-(year-1)/100+(year-1)/400+days+1; printf("%d-%d\n",year,month); printf(" Sun Mon Tue Wed Thu Fri Sat\n"); for (i=0;i<d%7;i++) printf(" "); for (i=1;i<=7-d%7;i++) { day++; printf("%5d",day); } printf("\n"); while(1) { for (i=1;i<=7;i++) { day++; if (day>m_day(year,month)) {getch();return 0;} printf("%5d",day); } printf("\n"); } } 本程序在给定年月,可以输出月历.如果有问题请联系我 QQ:303890400 说明 printf(" "); 是5个空格的.
这个也来问,我真是服了你了!!

所有的作业可以抄别人的,惟独计算机的作业一定要自己动手,无论你是哪个专业的,C一定懂一点,会有莫大的好处。

 

你自己用Turbo C++ 3.0编写的这个程序已经就很好了,可以完成全年月历及某月月历的打印,就你现在这个程序,我看完全可以在TC2.0下编译通过,试试吧。

 

 

纠正!!!

 

一年不是365天5小时46秒

应该是:365天5小时48分46秒

参与评论
相关内容
关于我们 | 隐私政策 | 站点地图 | 站长博客|京ICP备07025396号
添加到百度搜藏 添加到百度搜藏 电脑知识爱好者Copyright ?2006-2008版权所有 我要啦免费统计