c语言一年日历程序,用C语言写一个小程序,输出1个日历

匿名用户

1级

2007-04-01 回答

void print(int n)

{

int i;

for(i=0;i

}

int day(int year)

{

long a,b;

if(year<=2000)

{a=2000-year;b=6-(a+a/4-a/100+a/400)%7; return b;}

else {a=year-2000; b=(a+1+(a-1)/4-(a-1)/100+(a-1)/400)%7+6; return b%7;}

}

#define X " Sun Mon Tue Wed Thu Fri Sat"

#define P printf

#define B break

#define FP fprintf

#include

void main()

{

int i,j,k,m,n,f1,f2,year,d;

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

char fname[12];

FILE *fw;

clrscr();

P(" Input the year:");

scanf("%d",&year); /*input year*/

P(" Input the file name:");

scanf("%s",fname); P("\n"); /*Input the file name*/

fw=fopen(fname,"w+");

if(fw==NULL) {P(" can not open file."); return;}

P(" The calendar of the year %d.\n",year);

FP(fw," The calendar of the year %d.\n",year);

d=day(year);

if((year%4==0&&year%100!=0)||year%400==0) a[2]++; /*闰年2月有29天*/

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

{m=0; n=0; f1=0; f2=0;

switch(i)

{case 1:P(" Januray 1 "); FP(fw," Januray 1 "); B; /*fprintf函数的功能是将数据输出到文件中,因此在fprintf函数中多了一个文件指针*/

case 3:P(" March 3 "); FP(fw," March 3 "); B;

case 5:P(" May 5 "); FP(fw," May 5 "); B;

case 7:P(" July 7 "); FP(fw," July 7 "); B;

case 9:P(" September 9 "); FP(fw," September 9 "); B;

case 11:P(" Nevember 11 "); FP(fw," Nevember 11 "); B;

}

print(21); /*调用函数print,输出空格*/

for(k=0;k<21;k++) fprintf(fw," ");

switch(i+1)

{case 2:P(" February 2 "); FP(fw," February 2 ");B;

case 4:P(" April 4 "); FP(fw," April 4 ");B;

case 6:P(" June 6 "); FP(fw," June 6 ");B;

case 8:P(" August 8 "); FP(fw," August 8 "); B;

case 10:P(" October 10 "); FP(fw," October 10 ");B;

case 12:P(" December 12"); FP(fw," December 12");B;

}

P("\n"); fprintf(fw,"\n");

P(X); fprintf(fw,X);

print(6);fprintf(fw," ");

P(X); fprintf(fw,X);

fprintf(fw,"\n"); P("\n");

for(j=0;j<6;j++)

{if(j==0) {print(d*4); for(k=0;k

for(k=0;k<7-d;k++) {P("%4d",++m); fprintf(fw,"%4d",m);}

print(6); fprintf(fw," ");

d+=a[i]%7; d%=7;

print(d*4); for(k=0;k

for(k=0;k<7-d;k++) {P("%4d",++n); fprintf(fw,"%4d",n);}

P("\n"); fprintf(fw,"\n");

}

else{for(k=0;k<7;k++)

{if(m

else {print(4); fprintf(fw," ");}

if(m==a[i]) f1=1;

}

print(6); fprintf(fw," ");

for(k=0;k<7;k++)

{if(n

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值