C语言写的日历程序

2022-10-06 01:29:19   文档大全网     [ 字体: ] [ 阅读: ]

#文档大全网# 导语】以下是®文档大全网的小编为您整理的《C语言写的日历程序》,欢迎阅读!
日历,语言,程序

#include <stdio.h>

#include <windows.h>

int monthday[12]={31,28,31,30,31,30,31,31,30,31,30,31};

char *mouthname[12]={"Januray 1","February 2","March 3",

"April 4","May 5","June 6",

"July 7","August 8","September 9",

"October 10","November 11","December 12"};

/* 求相应年月日开始的天数 */

int week(int y,int m,int d)

{

int w;

if((m==1)||(m==2))

{

y--;

m+=12;

}

w=(d+2*m+3*(m+1)/5+y+y/4-y/100+y/400+1)%7;

return (w);

}

void main()

{

int y,w,i,m=1,d=1,d2=1;

while(1)

{

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

scanf("%d",&y);

if(y==0)break;

if (y%4==0&&y%100!=0) monthday[1]=29;

for(m=1;m<=11;m++)

{

printf("\n%-27s",mouthname[m-1]);

printf("\t%-27s\n",mouthname[m]);

printf("Sun Mon Tue Wed Thu Fri Sat");

printf("\tSun Mon Tue Wed Thu Fri Sat\n");

d2=1;

for(d=1;d<=monthday[m-1];d++)

{

w=week(y,m,d);

if(d==1)

for (i=0;i<w;i++) printf(" ");

printf("%3d ",d);

if(w==6)

{

printf("\t");

for(;d2<=monthday[m];d2++)

{

w=week(y,m+1,d2);

if(d2==1)

for (i=0;i<w;i++) printf(" ");

printf("%3d ",d2);

if(w==6)

{

d2++;

break;

}

}

printf(" \n");

}

}

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

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

}

}

}

本文来源:https://www.wddqxz.cn/70f87f28915f804d2b16c13e.html

相关推荐