万年历小系统制作
#import <Foundation/Foundation.h>
void query(int year,int month)
{
int century,result,num=1 ;
int day=1 ;
int a[2 ][13 ]={{0 ,31 ,29 ,31 ,30 ,31 ,30 ,31 ,31 ,30 ,31 ,30 ,31 },{0 ,31 ,28 ,31 ,30 ,31 ,30 ,31 ,31 ,30 ,31 ,30 ,31 }};
int year1=year,month1=month;
century = year/100 ;
year =year%100 ;
if (month<3 )
{
month +=12 ;
year -=1 ;
}
result = (year +year/4 +century/4 -2 *century+26 *(month+1 )/10 +day-1 )%7 ;
if (result==0 )
{
result=7 ;
}
for (int j=1 ; j<=7 ; j++) {
printf ("星期%d\t" ,j);
}
printf ("\n" );
for (int i=1 ; i<=6 ; i++) {
for (int j=1 ; j<=7 ; j++) {
if ((year1%4 ==0 &&year1%4 !=0 )||year1%400 ==0 ){
if (a[0 ][month1]<num) {
break ;
}
}
else
{
if (a[1 ][month1]<num) {
break ;
}
}
if (j>=result||i!=1 ) {
printf (" %d\t\t" ,num++);
}
else
{
printf ("\t\t" );
}
}
printf ("\n" );
}
}
int main(int argc, const char * argv[]) {
@autoreleasepool {
int year,month;
int booll=1 ;
printf (" -------------------------------\n" );
int option;
for (int i=0 ; i<2 ; i++) {
if (i==0 ) {
printf ("|\t\t万年历小系统!\t\t\t\t|\n" );
printf ("|\t使用说明:1是打印月历\t\t\t|\n" );
printf ("|\t使用说明:0退出\t\t\t\t|\n" );
}
else
{
printf ("|\t\t\t\t\t\t\t\t|\n" );
}
}
printf (" -------------------------------\n" );
while (1 ) {
printf (" 请输入你查询的信息:" );
scanf ("%d" ,&option);
switch (option) {
case 1 :
printf ("请输入某年某月(例如:2015.12)" );
scanf ("%d.%d" ,&year,&month);
query(year,month);
break ;
case 0 :
booll=0 ;
break ;
default :
printf ("输入错误,请重新输入" );
break ;
}
if (booll==0 ) {
break ;
}
printf (" -------------------------------\n" );
}
printf ("\t\t成功退出系统" );
}
return 0 ;
}