C语言用函数打印日历 c语言打印日历( 二 )


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==1month2) result++;
再把凡是紧跟在return后面的break删除;在system("pause")前加一句printf("\n")就OK了……
用c语言编写日历,这段有哪位大神能详细解释一下吗???# include stdio.h
# 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==0year%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\x0d\x0avoid main() \x0d\x0a{ \x0d\x0aint i,j,k,year,week; \x0d\x0aint day[]={31,28,31,30,31,30,31,31,30,31,30,31}; \x0d\x0achar month[12][10]={"January","February","March","April","May","June","July","August","September","October","November","December"}; \x0d\x0a\x0d\x0aprintf("Input year you want to print:"); \x0d\x0ascanf("%d",year); \x0d\x0a\x0d\x0aif((year%4==0year%100!=0)||(year%400==0)) day[1]++; //判断是否闰年\x0d\x0aweek=(35+year+year/4-year/100+year/400)%7; //计算当年的1月1日是周几的公式 \x0d\x0a\x0d\x0afor(i=0;i=7) \x0d\x0a{ \x0d\x0aprintf("\n"); \x0d\x0aweek=week%7; \x0d\x0a} \x0d\x0a} \x0d\x0aprintf("\n"); \x0d\x0a} \x0d\x0a}
利用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;

推荐阅读