关闭

日历,未完成

标签: 日历C
497人阅读 评论(0) 收藏 举报
分类:
#include "stdio.h"
#include <stdlib.h>
int Leap(int x)
{
if((x%400 == 0)||((x%4 == 0) && (x%100 != 0)) )//闰年
return 366;
else
return 365;
}
int monfun(int year,int mon)
{
if(Leap(year) == 366)//闰年
{
switch (mon)
{
case 1:mon = 31;break;
case 2:mon = 29;break;
case 3:mon = 31;break;
case 4:mon = 30;break;
case 5:mon = 31;break;
case 6:mon = 30;break;
case 7:mon = 31;break;
case 8:mon = 31;break;
case 9:mon = 30;break;
case 10:mon = 31;break;
case 11:mon = 30;break;
case 12:mon = 31;break;
}
}
else //非闰年
switch (mon)
{
case 1:mon = 31;break;
case 2:mon = 28;break;
case 3:mon = 31;break;
case 4:mon = 30;break;
case 5:mon = 31;break;
case 6:mon = 30;break;
case 7:mon = 31;break;
case 8:mon = 31;break;
case 9:mon = 30;break;
case 10:mon = 31;break;
case 11:mon = 30;break;
case 12:mon = 31;break;
}
return mon;
}
char space(int n)
{
for(int i = 0;i < n;++i)
{
return ' ';
}
}
int mon_day(int year,int n)
{
int des;
switch(n)
{
case 1:des = 0;break;
case 2:des = monfun(year,n)-1;break;
case 3:des = monfun(year,n)+monfun(year,n-1);break;
case 4:des = monfun(year,n)+monfun(year,n-1)+monfun(year,n-2);break;
case 5:des = monfun(year,n)+monfun(year,n-1)+monfun(year,n-2)+monfun(year,n-3);break;
case 6:des = monfun(year,n)+monfun(year,n-1)+monfun(year,n-2)+monfun(year,n-3)+monfun(year,n-4);break;
case 7:des = monfun(year,n)+monfun(year,n-1)+monfun(year,n-2)+monfun(year,n-3)+monfun(year,n-4)+monfun(year,n-5);break;
case 8:des = monfun(year,n)+monfun(year,n-1)+monfun(year,n-2)+monfun(year,n-3)+monfun(year,n-4)+monfun(year,n-5)+monfun(year,n-6);break;
case 9:des = monfun(year,n)+monfun(year,n-1)+monfun(year,n-2)+monfun(year,n-3)+monfun(year,n-4)+monfun(year,n-5)+
  monfun(year,n-6)+monfun(year,n-7);break;
case 10:des = monfun(year,n)+monfun(year,n-1)+monfun(year,n-2)+monfun(year,n-3)+monfun(year,n-4)+monfun(year,n-5)+
  monfun(year,n-6)+monfun(year,n-7)+monfun(year,n-8);break;
case 11:des = monfun(year,n)+monfun(year,n-1)+monfun(year,n-2)+monfun(year,n-3)+monfun(year,n-4)+monfun(year,n-5)+
  monfun(year,n-6)+monfun(year,n-7)+monfun(year,n-8)+monfun(year,n-9);break;
case 12:des =monfun(year,n)+monfun(year,n-1)+monfun(year,n-2)+monfun(year,n-3)+monfun(year,n-4)+monfun(year,n-5)+
  monfun(year,n-6)+monfun(year,n-7)+monfun(year,n-8)+monfun(year,n-9)+monfun(year,n-10);break;

}
return des;
}
void main()
{
int year,month;
while(1)
{
printf("\n请输入年月!\n");
scanf("%d%d",&year,&month);
int tab = ((year -1)*Leap(year) + mon_day(year,month))%7 ;
printf("\n\t\t%d年\t\t%d月",year,month);
printf("\n日\t一\t二\t三\t四\t五\t六\n");
//space(tab);
int mon[35] = {0};
for(int i = 0;i<35;i++)//monfun(year,month)+1
{
if(i<tab+1)
{
mon[i] = 0;
}
if(i>=(tab+1)&&i<monfun(year,month)+tab+1)
{
mon[i] = i-tab;
}
else 
mon[i] = 0;
}
for(int i = 0;i<35;i++)
{
if(mon[i]==0)
{
printf("\t");
}
if(i%7==0)
{
printf("\n");
}
else
printf("%d",mon[i]);
}


}


}

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:14486次
    • 积分:306
    • 等级:
    • 排名:千里之外
    • 原创:16篇
    • 转载:1篇
    • 译文:0篇
    • 评论:0条
    文章分类