third commit

master
1282855823@qq.com 6 years ago
parent 6e01d8c284
commit 3307655dcb

@ -0,0 +1,178 @@
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<>
// 每月天数
#include<math.h>
int month_day(int year,int month)
{
switch(month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
return 31;break;
case 4:
case 6:
case 9:
case 11:
return 30;break;
case 2:
if((year%4==0)&&(year%100!=0)||(year%400==0))
{
return 29;
break;
}
else
{
return 28;
break;
}
}
}
// 年历
void year_calendar(int year)
{
int month,days,weekday,sum_day;
int i,j;
year;
printf("请输入要查询的年份:");
scanf("%d",&year);
for(i=1;i<year;i++)
{
if((year%4==0)&&(year%100!=0)||(year%400==0))
sum_day+=366;
else
sum_day+=365;
}
for(month=1;month<=12;month++)
{
printf("\n--------%d/%d--------\n",year,month);
printf("SUN\tMON\tTUE\tWED\tTHU\tFRI\tSAT\t\n");
i=1;
j=1;
weekday=sum_day%7;
while(i<=weekday) //开始位置前都是空格
{
printf("\t");
i++;
}
while(j<=month_day(year,month))
{
weekday=sum_day%7;
if (weekday==6)
printf("%d\n",j);
else
printf("%d\t",j);
if(j==month_day(year,month))
printf("\n");
j++;
sum_day++;
}
}
}
// 月历
void month_calendar(int year,int month)
{
int sum_day=0,weekday,i,j,k;
printf("请输入要查询的年/月:");
scanf("%d/%d",&year,&month);
for(i=1;i<year;i++)
{
if((year%4==0)&&(year%100!=0)||(year%400==0))
sum_day+=366;
else
sum_day+=365;
}
for(k=1;k<month;k++)
{
sum_day+=month_day(year,month);
}
printf("\n--------%d/%d--------\n",year,month);
printf("SUN\tMON\tTUE\tWED\tTHU\tFRI\tSAT\t\n");
i=1;
j=1;
weekday=sum_day%7;
while(i<=weekday) //开始位置前都是空格
{
printf("\t");
i++;
}
while(j<=month_day(year,month))
{
weekday=sum_day%7;
if (weekday==6)
printf("%d\n",j);
else
printf("%d\t",j);
if(j==month_day(year,month))
printf("\n");
j++;
sum_day++;
}
}
// 距今多少天
struct tm
{
int tm_sec;
int tm_min;
int tm_hour;
int tm_day;
int tm_month;
int tm_year;
int tm_weekday;
int tm_yearday;
}
int main(void)
{
printf("\n-------------------选择服务-------------------\n\n");
printf(" 1.年历显示\n");
printf(" 2.月历显示\n");
printf(" 3.日期查询\n");
printf(" 4.距今多少天\n");
printf(" 5.退出\n");
printf("\n-------------------选择服务-------------------\n") ;
int n,year,month,day;
printf("请选择服务:");
scanf("%d",&n);
switch(n)
{
case 1:
{
year_calendar(year);
break;
}
case 2:
{
month_calendar(year,month);
break;
}
}
}
Loading…
Cancel
Save