基本要求:
1.自行设计界面,要求用户输入要查询的日期,年份在1980~2099之间,按ESC程序结束。
2.根据用户输入值,将当年的年历在屏幕上显示。
3.显示格式为:在最上方显示年份,将12个月按照3列4行的分布显示出来,即第一大行显示1、2、3月,第二大行显示4、5、6月 ...;每个月都要显示代表星期几的抬头:Su Mo Tu We Th Fr Sa ,然后将本月的每一天按照顺序显示出来。周六、周日、法定节假日以红色字符显示,若用户输入了查询的具体日期,则将其以醒目颜色显示;若用户只输入了年份,则以当前的月日在年历上标记;若用户只输入了年、月,则以当前的日期在年历上标记。要求显示界面清晰、直观。
4.按任意键返回主界面。
高分悬赏。。。。如有正确回答出者,小妹必有重谢!非诚勿扰
9 个解决方案
#1
记号,我也想知道C有没有这个函数。
#2
原来的,可以看看。#include <stdio.h>
#include <conio.h>
int main()
{
for(;;)
{
int nian,yue,a,b,m,c,_m=28;
long e;
printf("请输入年份:");
scanf("%d",&nian);
e=nian;
e=e-1;
e=(e*365+e/4)%7;
m=e;
if((nian%4==0)||(nian%100==0)&&(nian%400!=0))
_m++;
printf("%d的日历:",nian);
for(yue=1;yue<=12;yue++)
{
if(yue==1||yue==3||yue==5||yue==7||yue==8||yue==10||yue==12)
{
c=0;
printf("\n");
printf(" %d月 \n",yue);
printf(" 日 一 二 三 四 五 六\n");
for(b=1;b<=m;b++)
{
c++;
printf(" ");
}
for(a=1;a<=31;a++)
{
c++;
if(c%7-1==0&&c!=1)
printf("\n");
if(a<10)
printf(" ");
printf(" %d ",a);
m++;
if(m==7)
m=0;
}
printf("\n");
}
else
{
if(yue==4||yue==6||yue==9||yue==11||yue==2)
{
if(yue==2)
{
c=0;
printf("\n");
printf(" %d月 \n",yue);
printf(" 日 一 二 三 四 五 六\n");
for(b=1;b<=m;b++)
{
c++;
printf(" ");
}
for(a=1;a<=_m;a++)
{
c++;
if(c%7-1==0&&c!=1)
printf("\n");
if(a<10)
printf(" ");
printf(" %d ",a);
m++;
if(m==7)
m=0;
}
printf("\n");
}
else
{
c=0;
printf("\n");
printf(" %d月 \n",yue);
printf(" 日 一 二 三 四 五 六\n");
for(b=1;b<=m;b++)
{
c++;
printf(" ");
}
for(a=1;a<=30;a++)
{
c++;
if(c%7-1==0&&c!=1)
printf("\n");
if(a<10)
printf(" ");
printf(" %d ",a);
m++;
if(m==7)
m=0;
}
printf("\n");
}
}
}
}
}
}
#include <conio.h>
int main()
{
for(;;)
{
int nian,yue,a,b,m,c,_m=28;
long e;
printf("请输入年份:");
scanf("%d",&nian);
e=nian;
e=e-1;
e=(e*365+e/4)%7;
m=e;
if((nian%4==0)||(nian%100==0)&&(nian%400!=0))
_m++;
printf("%d的日历:",nian);
for(yue=1;yue<=12;yue++)
{
if(yue==1||yue==3||yue==5||yue==7||yue==8||yue==10||yue==12)
{
c=0;
printf("\n");
printf(" %d月 \n",yue);
printf(" 日 一 二 三 四 五 六\n");
for(b=1;b<=m;b++)
{
c++;
printf(" ");
}
for(a=1;a<=31;a++)
{
c++;
if(c%7-1==0&&c!=1)
printf("\n");
if(a<10)
printf(" ");
printf(" %d ",a);
m++;
if(m==7)
m=0;
}
printf("\n");
}
else
{
if(yue==4||yue==6||yue==9||yue==11||yue==2)
{
if(yue==2)
{
c=0;
printf("\n");
printf(" %d月 \n",yue);
printf(" 日 一 二 三 四 五 六\n");
for(b=1;b<=m;b++)
{
c++;
printf(" ");
}
for(a=1;a<=_m;a++)
{
c++;
if(c%7-1==0&&c!=1)
printf("\n");
if(a<10)
printf(" ");
printf(" %d ",a);
m++;
if(m==7)
m=0;
}
printf("\n");
}
else
{
c=0;
printf("\n");
printf(" %d月 \n",yue);
printf(" 日 一 二 三 四 五 六\n");
for(b=1;b<=m;b++)
{
c++;
printf(" ");
}
for(a=1;a<=30;a++)
{
c++;
if(c%7-1==0&&c!=1)
printf("\n");
if(a<10)
printf(" ");
printf(" %d ",a);
m++;
if(m==7)
m=0;
}
printf("\n");
}
}
}
}
}
}
#3
标准C语言time_t类型支持的时间范围是1970~2038年。
#4
网上好多啊,我曾经下载了三个版本,大同小异,需要修改的,就增加一些函数完成一些功能即可
#5
哎呀,网上太多了,我给你一个:
[code=C/C+#include] <stdio.h>
#include <stdlib.h>
#include <conio.h>
#define X " Sun Mon Tue Wed Thu Fri Sat"
void menu()
{
system("cls");
printf("\nTHIS IS THE MENU OF THE PROGRAM !");
printf("\nYOU CAN CHOOSE THE NUMBER FOR THE FUNCTIOM:");
printf("\n\n");
printf("1 Find the day by year-month-date.\n");
printf("2 Find the year you input if the leap year.\n");
printf("3 Print the calendar of the year you input.\n");
printf("4 Exit.\n\n");
printf("Input your choice:");
}
int getday(int year,int month,int date)
{
int flag,s,i;
int a[13={0,31,28,31,30,31,30,31,31,30,31,30,31};
int cont=0;
flag=isleap(year);
if(flag==1)
a[2]++;
for(i=1;i<month;i++)
{
cont=cont+a[i];
}
cont=cont+date;
s=year+1+(year-1)/4+(year-1)/100+(year-1)/400+cont;
return s%7;
}
int isleap(int year)
{
if(year%4==0&&year%100||year%400==0)
return 1;
else
return 0;
}
void print(int n)
{
int i;
for(i=0;i<n;i++) printf(" ");
}
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;
}
}
void printcalendar(int year)
{
int i,j,k,m,n,f1,f2,d;
int a[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
printf("\nThe calendar of the year %d.\n\n",year);
d=day(year);
if(isleap(year)==1)
a[2]++;
for(i=1;i<=12;i+=2)
{
m=0; n=0; f1=0; f2=0;
switch(i)
{
case 1:printf(" Januray 1 ");break;
case 3:printf(" March 3 ");break;
case 5:printf(" May 5 ");break;
case 7:printf(" July 7 "); break;
case 9:printf(" September 9 ");break;
case 11:printf(" Nevember 11 ");break;
}
print(21);
switch(i+1)
{
case 2:printf(" February 2 "); break;
case 4:printf(" April 4 "); break;
case 6:printf(" June 6 "); break;
case 8:printf(" August 8 "); break;
case 10:printf(" October 10 "); break;
case 12:printf(" December 12"); break;
}
printf("\n");
printf(X);
print(6);
printf(X);
printf("\n");
for(j=0;j<6;j++)
{
if(j==0)
{
print(d*4);
for(k=0;k<7-d;k++)
{
printf("%4d",++m);
}
print(6);
d+=a[i]%7;
d%=7;
print(d*4);
for(k=0;k<7-d;k++)
{
printf("%4d",++n);
}
printf("\n");
}
else
{
for(k=0;k<7;k++)
{
if(m<a[i])
{
printf("%4d",++m);
}
else
{
print(4);
}
if(m==a[i]) f1=1;
}
print(6);
for(k=0;k<7;k++)
{
if(n<a[i+1])
{
printf("%4d",++n);
}
else
{
print(4);
}
if(n==a[i+1]) f2=1;
}
printf("\n");
if(f1&&f2) break;
}
}
d+=a[i+1]%7;
d%=7;
printf(" ");
for(k=0;k<27;k++)
{
printf("=");
}
print(6);
printf(" ");
for(k=0;k<27;k++)
{
printf("=");
}
printf("\n");
if(i==5)
{
printf("Press any key to others!");
getch();
system("cls");
}
}
}
void main()
{
int choice;
int year,month,date;
int day,flag;
char con;
menu();
scanf("%d",&choice);
if(choice==1)
{
r1:system("cls");
printf("\nPlease input the year-month-date(XXXX,XX,XX):");
scanf("%d,%d,%d",&year,&month,&date);
day=getday(year,month,date);
if(day==0)
printf("\n%d-%d-%d is Sunday!\n",year,month,date);
if(day==1)
printf("\n%d-%d-%d is Monday!\n",year,month,date);
if(day==2)
printf("\n%d-%d-%d is Tuesday!\n",year,month,date);
if(day==3)
printf("\n%d-%d-%d is Wednesday!\n",year,month,date);
if(day==4)
printf("\n%d-%d-%d is Thursday!\n",year,month,date);
if(day==5)
printf("\n%d-%d-%d is Friday!\n",year,month,date);
if(day==6)
printf("\n%d-%d-%d is Saturday!\n",year,month,date);
printf("\nContinue...(Y/N)");
con=getch();
if((con=='y')||(con=='Y'))
goto r1;
if((con=='n')||(con=='N'))
main();
}
if(choice==2)
{
r2:system("cls");
printf("\nPlease input the year(XXXX):");
scanf("%d",&year);
flag=isleap(year);
if(flag==1)
printf("\nThe year %d is leap year!\n",year);
if(flag==0)
printf("\nThe year %d is not leap year!\n",year);
printf("\nContinue...(Y/N)");
con=getch();
if((con=='y')||(con=='Y'))
goto r2;
if((con=='n')||(con=='N'))
main();
}
if(choice==3)
{
r3:system("cls");
printf("\nPlease input the year(XXXX):");
scanf("%d",&year);
printcalendar(year);
printf("Continue...(Y/N)");
con=getch();
if((con=='y')||(con=='Y'))
goto r3;
if((con=='n')||(con=='N'))
main();
}
if(choice==4)
{
system("cls");
printf("\nDo you want to Exit?(Y/N)");
con=getch();
if((con=='y')||(con=='Y'))
return;
if((con=='n')||(con=='N'))
main();
}
}
+][/code]
[code=C/C+#include] <stdio.h>
#include <stdlib.h>
#include <conio.h>
#define X " Sun Mon Tue Wed Thu Fri Sat"
void menu()
{
system("cls");
printf("\nTHIS IS THE MENU OF THE PROGRAM !");
printf("\nYOU CAN CHOOSE THE NUMBER FOR THE FUNCTIOM:");
printf("\n\n");
printf("1 Find the day by year-month-date.\n");
printf("2 Find the year you input if the leap year.\n");
printf("3 Print the calendar of the year you input.\n");
printf("4 Exit.\n\n");
printf("Input your choice:");
}
int getday(int year,int month,int date)
{
int flag,s,i;
int a[13={0,31,28,31,30,31,30,31,31,30,31,30,31};
int cont=0;
flag=isleap(year);
if(flag==1)
a[2]++;
for(i=1;i<month;i++)
{
cont=cont+a[i];
}
cont=cont+date;
s=year+1+(year-1)/4+(year-1)/100+(year-1)/400+cont;
return s%7;
}
int isleap(int year)
{
if(year%4==0&&year%100||year%400==0)
return 1;
else
return 0;
}
void print(int n)
{
int i;
for(i=0;i<n;i++) printf(" ");
}
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;
}
}
void printcalendar(int year)
{
int i,j,k,m,n,f1,f2,d;
int a[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
printf("\nThe calendar of the year %d.\n\n",year);
d=day(year);
if(isleap(year)==1)
a[2]++;
for(i=1;i<=12;i+=2)
{
m=0; n=0; f1=0; f2=0;
switch(i)
{
case 1:printf(" Januray 1 ");break;
case 3:printf(" March 3 ");break;
case 5:printf(" May 5 ");break;
case 7:printf(" July 7 "); break;
case 9:printf(" September 9 ");break;
case 11:printf(" Nevember 11 ");break;
}
print(21);
switch(i+1)
{
case 2:printf(" February 2 "); break;
case 4:printf(" April 4 "); break;
case 6:printf(" June 6 "); break;
case 8:printf(" August 8 "); break;
case 10:printf(" October 10 "); break;
case 12:printf(" December 12"); break;
}
printf("\n");
printf(X);
print(6);
printf(X);
printf("\n");
for(j=0;j<6;j++)
{
if(j==0)
{
print(d*4);
for(k=0;k<7-d;k++)
{
printf("%4d",++m);
}
print(6);
d+=a[i]%7;
d%=7;
print(d*4);
for(k=0;k<7-d;k++)
{
printf("%4d",++n);
}
printf("\n");
}
else
{
for(k=0;k<7;k++)
{
if(m<a[i])
{
printf("%4d",++m);
}
else
{
print(4);
}
if(m==a[i]) f1=1;
}
print(6);
for(k=0;k<7;k++)
{
if(n<a[i+1])
{
printf("%4d",++n);
}
else
{
print(4);
}
if(n==a[i+1]) f2=1;
}
printf("\n");
if(f1&&f2) break;
}
}
d+=a[i+1]%7;
d%=7;
printf(" ");
for(k=0;k<27;k++)
{
printf("=");
}
print(6);
printf(" ");
for(k=0;k<27;k++)
{
printf("=");
}
printf("\n");
if(i==5)
{
printf("Press any key to others!");
getch();
system("cls");
}
}
}
void main()
{
int choice;
int year,month,date;
int day,flag;
char con;
menu();
scanf("%d",&choice);
if(choice==1)
{
r1:system("cls");
printf("\nPlease input the year-month-date(XXXX,XX,XX):");
scanf("%d,%d,%d",&year,&month,&date);
day=getday(year,month,date);
if(day==0)
printf("\n%d-%d-%d is Sunday!\n",year,month,date);
if(day==1)
printf("\n%d-%d-%d is Monday!\n",year,month,date);
if(day==2)
printf("\n%d-%d-%d is Tuesday!\n",year,month,date);
if(day==3)
printf("\n%d-%d-%d is Wednesday!\n",year,month,date);
if(day==4)
printf("\n%d-%d-%d is Thursday!\n",year,month,date);
if(day==5)
printf("\n%d-%d-%d is Friday!\n",year,month,date);
if(day==6)
printf("\n%d-%d-%d is Saturday!\n",year,month,date);
printf("\nContinue...(Y/N)");
con=getch();
if((con=='y')||(con=='Y'))
goto r1;
if((con=='n')||(con=='N'))
main();
}
if(choice==2)
{
r2:system("cls");
printf("\nPlease input the year(XXXX):");
scanf("%d",&year);
flag=isleap(year);
if(flag==1)
printf("\nThe year %d is leap year!\n",year);
if(flag==0)
printf("\nThe year %d is not leap year!\n",year);
printf("\nContinue...(Y/N)");
con=getch();
if((con=='y')||(con=='Y'))
goto r2;
if((con=='n')||(con=='N'))
main();
}
if(choice==3)
{
r3:system("cls");
printf("\nPlease input the year(XXXX):");
scanf("%d",&year);
printcalendar(year);
printf("Continue...(Y/N)");
con=getch();
if((con=='y')||(con=='Y'))
goto r3;
if((con=='n')||(con=='N'))
main();
}
if(choice==4)
{
system("cls");
printf("\nDo you want to Exit?(Y/N)");
con=getch();
if((con=='y')||(con=='Y'))
return;
if((con=='n')||(con=='N'))
main();
}
}
+][/code]
#6
今年Feb月的时候的练习:
#include <stdio.h>
#include <stdbool.h>
//Define Global Variables
int year,month,numberDays,weekFirstDay,lastDay;
int daysPerMonth[12]={ 31,28,31,30,31,30,31,31,30,31,30,31 };
bool leapFlag;
//Declare some Functions in the Program.
void space (void);
void dispcal (void);
bool leapYear (void);
int numbersOfMonth (void);
int weekOfFirstday (void);
int sumDay (int n);
//Main Program Start...
int main (void) {
printf ("please date[year month]:");
scanf ("%i%i",&year,&month);
printf ("\n");
//Call Functions.
//weekOfFirstday():Get week of Current Month First day.
//numbersOfMonth():Get numbers of Current Month.
//dispcal(weekFirstDay):display Cureent month calendar.
weekOfFirstday();
numbersOfMonth();
dispcal();
//Return OS.
return 0;
}
//
int weekOfFirstday (void) {
switch (month) {
case 1: numberDays=1;break;
case 2:numberDays=sumDay(2);break;
case 3:numberDays=sumDay(3);break;
case 4:numberDays=sumDay(4);break;
case 5:numberDays=sumDay(5);break;
case 6:numberDays=sumDay(6);break;
case 7:numberDays=sumDay(7);break;
case 8:numberDays=sumDay(8);break;
case 9:numberDays=sumDay(9);break;
case 10:numberDays=sumDay(10);break;
case 11:numberDays=sumDay(11);break;
case 12:numberDays=sumDay(12);break;
}
if(leapYear()==true&&month>2) {
numberDays+=1;
}
weekFirstDay=((year-1)*365+(year-1)/4-(year-1)/100+(year-1)/400+numberDays)%7;
return weekFirstDay;
}
//
int sumDay (int n) {
int i,sum=1;
for(i=0;i<(n-1);i++) {
sum += daysPerMonth[i];
}
return sum;
}
void space (void) {
int i;
for(i=0;i<weekFirstDay;i++) {
printf ("\t");
}
}
//
void dispcal (void) {
int index,col,firstDay=1;
printf ("---------------------------------------------------\n");
printf ("Sun\tMon\tTue\tWed\tThu\tFri\tSat\n\n");
space();
for(col=1;col<=7-weekFirstDay;col++,firstDay++) {
printf ("%i\t",firstDay);
}
printf ("\n\n");
for(index=1,col=firstDay;col<=lastDay;col++,index++) {
printf ("%i\t",col);
if(index%7==0) {
printf ("\n\n");
}
}
printf ("\n--------------------------------------------------\n");
}
//
bool leapYear (void) {
if(((year%4==0&&year%100!=0)||year%400==0)&&month==2) {
leapFlag=true;
}else{
leapFlag=false;
}
return leapFlag;
}
//
int numbersOfMonth (void) {
if(leapYear()==true) {
lastDay=daysPerMonth[month-1]+1;
}else{
lastDay=daysPerMonth[month-1];
}
return lastDay;
}
root@~/prog #./cale
please date[year month]:2011 6
---------------------------------------------------
Sun Mon Tue Wed Thu Fri Sat
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30
--------------------------------------------------
root@~/prog #
#7
该不会以身相许吧?
#8
就第一个没有错误、那两个都有错误。还有、没有红色字体啊、、一定要有这个的!
#1
记号,我也想知道C有没有这个函数。
#2
原来的,可以看看。#include <stdio.h>
#include <conio.h>
int main()
{
for(;;)
{
int nian,yue,a,b,m,c,_m=28;
long e;
printf("请输入年份:");
scanf("%d",&nian);
e=nian;
e=e-1;
e=(e*365+e/4)%7;
m=e;
if((nian%4==0)||(nian%100==0)&&(nian%400!=0))
_m++;
printf("%d的日历:",nian);
for(yue=1;yue<=12;yue++)
{
if(yue==1||yue==3||yue==5||yue==7||yue==8||yue==10||yue==12)
{
c=0;
printf("\n");
printf(" %d月 \n",yue);
printf(" 日 一 二 三 四 五 六\n");
for(b=1;b<=m;b++)
{
c++;
printf(" ");
}
for(a=1;a<=31;a++)
{
c++;
if(c%7-1==0&&c!=1)
printf("\n");
if(a<10)
printf(" ");
printf(" %d ",a);
m++;
if(m==7)
m=0;
}
printf("\n");
}
else
{
if(yue==4||yue==6||yue==9||yue==11||yue==2)
{
if(yue==2)
{
c=0;
printf("\n");
printf(" %d月 \n",yue);
printf(" 日 一 二 三 四 五 六\n");
for(b=1;b<=m;b++)
{
c++;
printf(" ");
}
for(a=1;a<=_m;a++)
{
c++;
if(c%7-1==0&&c!=1)
printf("\n");
if(a<10)
printf(" ");
printf(" %d ",a);
m++;
if(m==7)
m=0;
}
printf("\n");
}
else
{
c=0;
printf("\n");
printf(" %d月 \n",yue);
printf(" 日 一 二 三 四 五 六\n");
for(b=1;b<=m;b++)
{
c++;
printf(" ");
}
for(a=1;a<=30;a++)
{
c++;
if(c%7-1==0&&c!=1)
printf("\n");
if(a<10)
printf(" ");
printf(" %d ",a);
m++;
if(m==7)
m=0;
}
printf("\n");
}
}
}
}
}
}
#include <conio.h>
int main()
{
for(;;)
{
int nian,yue,a,b,m,c,_m=28;
long e;
printf("请输入年份:");
scanf("%d",&nian);
e=nian;
e=e-1;
e=(e*365+e/4)%7;
m=e;
if((nian%4==0)||(nian%100==0)&&(nian%400!=0))
_m++;
printf("%d的日历:",nian);
for(yue=1;yue<=12;yue++)
{
if(yue==1||yue==3||yue==5||yue==7||yue==8||yue==10||yue==12)
{
c=0;
printf("\n");
printf(" %d月 \n",yue);
printf(" 日 一 二 三 四 五 六\n");
for(b=1;b<=m;b++)
{
c++;
printf(" ");
}
for(a=1;a<=31;a++)
{
c++;
if(c%7-1==0&&c!=1)
printf("\n");
if(a<10)
printf(" ");
printf(" %d ",a);
m++;
if(m==7)
m=0;
}
printf("\n");
}
else
{
if(yue==4||yue==6||yue==9||yue==11||yue==2)
{
if(yue==2)
{
c=0;
printf("\n");
printf(" %d月 \n",yue);
printf(" 日 一 二 三 四 五 六\n");
for(b=1;b<=m;b++)
{
c++;
printf(" ");
}
for(a=1;a<=_m;a++)
{
c++;
if(c%7-1==0&&c!=1)
printf("\n");
if(a<10)
printf(" ");
printf(" %d ",a);
m++;
if(m==7)
m=0;
}
printf("\n");
}
else
{
c=0;
printf("\n");
printf(" %d月 \n",yue);
printf(" 日 一 二 三 四 五 六\n");
for(b=1;b<=m;b++)
{
c++;
printf(" ");
}
for(a=1;a<=30;a++)
{
c++;
if(c%7-1==0&&c!=1)
printf("\n");
if(a<10)
printf(" ");
printf(" %d ",a);
m++;
if(m==7)
m=0;
}
printf("\n");
}
}
}
}
}
}
#3
标准C语言time_t类型支持的时间范围是1970~2038年。
#4
网上好多啊,我曾经下载了三个版本,大同小异,需要修改的,就增加一些函数完成一些功能即可
#5
哎呀,网上太多了,我给你一个:
[code=C/C+#include] <stdio.h>
#include <stdlib.h>
#include <conio.h>
#define X " Sun Mon Tue Wed Thu Fri Sat"
void menu()
{
system("cls");
printf("\nTHIS IS THE MENU OF THE PROGRAM !");
printf("\nYOU CAN CHOOSE THE NUMBER FOR THE FUNCTIOM:");
printf("\n\n");
printf("1 Find the day by year-month-date.\n");
printf("2 Find the year you input if the leap year.\n");
printf("3 Print the calendar of the year you input.\n");
printf("4 Exit.\n\n");
printf("Input your choice:");
}
int getday(int year,int month,int date)
{
int flag,s,i;
int a[13={0,31,28,31,30,31,30,31,31,30,31,30,31};
int cont=0;
flag=isleap(year);
if(flag==1)
a[2]++;
for(i=1;i<month;i++)
{
cont=cont+a[i];
}
cont=cont+date;
s=year+1+(year-1)/4+(year-1)/100+(year-1)/400+cont;
return s%7;
}
int isleap(int year)
{
if(year%4==0&&year%100||year%400==0)
return 1;
else
return 0;
}
void print(int n)
{
int i;
for(i=0;i<n;i++) printf(" ");
}
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;
}
}
void printcalendar(int year)
{
int i,j,k,m,n,f1,f2,d;
int a[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
printf("\nThe calendar of the year %d.\n\n",year);
d=day(year);
if(isleap(year)==1)
a[2]++;
for(i=1;i<=12;i+=2)
{
m=0; n=0; f1=0; f2=0;
switch(i)
{
case 1:printf(" Januray 1 ");break;
case 3:printf(" March 3 ");break;
case 5:printf(" May 5 ");break;
case 7:printf(" July 7 "); break;
case 9:printf(" September 9 ");break;
case 11:printf(" Nevember 11 ");break;
}
print(21);
switch(i+1)
{
case 2:printf(" February 2 "); break;
case 4:printf(" April 4 "); break;
case 6:printf(" June 6 "); break;
case 8:printf(" August 8 "); break;
case 10:printf(" October 10 "); break;
case 12:printf(" December 12"); break;
}
printf("\n");
printf(X);
print(6);
printf(X);
printf("\n");
for(j=0;j<6;j++)
{
if(j==0)
{
print(d*4);
for(k=0;k<7-d;k++)
{
printf("%4d",++m);
}
print(6);
d+=a[i]%7;
d%=7;
print(d*4);
for(k=0;k<7-d;k++)
{
printf("%4d",++n);
}
printf("\n");
}
else
{
for(k=0;k<7;k++)
{
if(m<a[i])
{
printf("%4d",++m);
}
else
{
print(4);
}
if(m==a[i]) f1=1;
}
print(6);
for(k=0;k<7;k++)
{
if(n<a[i+1])
{
printf("%4d",++n);
}
else
{
print(4);
}
if(n==a[i+1]) f2=1;
}
printf("\n");
if(f1&&f2) break;
}
}
d+=a[i+1]%7;
d%=7;
printf(" ");
for(k=0;k<27;k++)
{
printf("=");
}
print(6);
printf(" ");
for(k=0;k<27;k++)
{
printf("=");
}
printf("\n");
if(i==5)
{
printf("Press any key to others!");
getch();
system("cls");
}
}
}
void main()
{
int choice;
int year,month,date;
int day,flag;
char con;
menu();
scanf("%d",&choice);
if(choice==1)
{
r1:system("cls");
printf("\nPlease input the year-month-date(XXXX,XX,XX):");
scanf("%d,%d,%d",&year,&month,&date);
day=getday(year,month,date);
if(day==0)
printf("\n%d-%d-%d is Sunday!\n",year,month,date);
if(day==1)
printf("\n%d-%d-%d is Monday!\n",year,month,date);
if(day==2)
printf("\n%d-%d-%d is Tuesday!\n",year,month,date);
if(day==3)
printf("\n%d-%d-%d is Wednesday!\n",year,month,date);
if(day==4)
printf("\n%d-%d-%d is Thursday!\n",year,month,date);
if(day==5)
printf("\n%d-%d-%d is Friday!\n",year,month,date);
if(day==6)
printf("\n%d-%d-%d is Saturday!\n",year,month,date);
printf("\nContinue...(Y/N)");
con=getch();
if((con=='y')||(con=='Y'))
goto r1;
if((con=='n')||(con=='N'))
main();
}
if(choice==2)
{
r2:system("cls");
printf("\nPlease input the year(XXXX):");
scanf("%d",&year);
flag=isleap(year);
if(flag==1)
printf("\nThe year %d is leap year!\n",year);
if(flag==0)
printf("\nThe year %d is not leap year!\n",year);
printf("\nContinue...(Y/N)");
con=getch();
if((con=='y')||(con=='Y'))
goto r2;
if((con=='n')||(con=='N'))
main();
}
if(choice==3)
{
r3:system("cls");
printf("\nPlease input the year(XXXX):");
scanf("%d",&year);
printcalendar(year);
printf("Continue...(Y/N)");
con=getch();
if((con=='y')||(con=='Y'))
goto r3;
if((con=='n')||(con=='N'))
main();
}
if(choice==4)
{
system("cls");
printf("\nDo you want to Exit?(Y/N)");
con=getch();
if((con=='y')||(con=='Y'))
return;
if((con=='n')||(con=='N'))
main();
}
}
+][/code]
[code=C/C+#include] <stdio.h>
#include <stdlib.h>
#include <conio.h>
#define X " Sun Mon Tue Wed Thu Fri Sat"
void menu()
{
system("cls");
printf("\nTHIS IS THE MENU OF THE PROGRAM !");
printf("\nYOU CAN CHOOSE THE NUMBER FOR THE FUNCTIOM:");
printf("\n\n");
printf("1 Find the day by year-month-date.\n");
printf("2 Find the year you input if the leap year.\n");
printf("3 Print the calendar of the year you input.\n");
printf("4 Exit.\n\n");
printf("Input your choice:");
}
int getday(int year,int month,int date)
{
int flag,s,i;
int a[13={0,31,28,31,30,31,30,31,31,30,31,30,31};
int cont=0;
flag=isleap(year);
if(flag==1)
a[2]++;
for(i=1;i<month;i++)
{
cont=cont+a[i];
}
cont=cont+date;
s=year+1+(year-1)/4+(year-1)/100+(year-1)/400+cont;
return s%7;
}
int isleap(int year)
{
if(year%4==0&&year%100||year%400==0)
return 1;
else
return 0;
}
void print(int n)
{
int i;
for(i=0;i<n;i++) printf(" ");
}
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;
}
}
void printcalendar(int year)
{
int i,j,k,m,n,f1,f2,d;
int a[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
printf("\nThe calendar of the year %d.\n\n",year);
d=day(year);
if(isleap(year)==1)
a[2]++;
for(i=1;i<=12;i+=2)
{
m=0; n=0; f1=0; f2=0;
switch(i)
{
case 1:printf(" Januray 1 ");break;
case 3:printf(" March 3 ");break;
case 5:printf(" May 5 ");break;
case 7:printf(" July 7 "); break;
case 9:printf(" September 9 ");break;
case 11:printf(" Nevember 11 ");break;
}
print(21);
switch(i+1)
{
case 2:printf(" February 2 "); break;
case 4:printf(" April 4 "); break;
case 6:printf(" June 6 "); break;
case 8:printf(" August 8 "); break;
case 10:printf(" October 10 "); break;
case 12:printf(" December 12"); break;
}
printf("\n");
printf(X);
print(6);
printf(X);
printf("\n");
for(j=0;j<6;j++)
{
if(j==0)
{
print(d*4);
for(k=0;k<7-d;k++)
{
printf("%4d",++m);
}
print(6);
d+=a[i]%7;
d%=7;
print(d*4);
for(k=0;k<7-d;k++)
{
printf("%4d",++n);
}
printf("\n");
}
else
{
for(k=0;k<7;k++)
{
if(m<a[i])
{
printf("%4d",++m);
}
else
{
print(4);
}
if(m==a[i]) f1=1;
}
print(6);
for(k=0;k<7;k++)
{
if(n<a[i+1])
{
printf("%4d",++n);
}
else
{
print(4);
}
if(n==a[i+1]) f2=1;
}
printf("\n");
if(f1&&f2) break;
}
}
d+=a[i+1]%7;
d%=7;
printf(" ");
for(k=0;k<27;k++)
{
printf("=");
}
print(6);
printf(" ");
for(k=0;k<27;k++)
{
printf("=");
}
printf("\n");
if(i==5)
{
printf("Press any key to others!");
getch();
system("cls");
}
}
}
void main()
{
int choice;
int year,month,date;
int day,flag;
char con;
menu();
scanf("%d",&choice);
if(choice==1)
{
r1:system("cls");
printf("\nPlease input the year-month-date(XXXX,XX,XX):");
scanf("%d,%d,%d",&year,&month,&date);
day=getday(year,month,date);
if(day==0)
printf("\n%d-%d-%d is Sunday!\n",year,month,date);
if(day==1)
printf("\n%d-%d-%d is Monday!\n",year,month,date);
if(day==2)
printf("\n%d-%d-%d is Tuesday!\n",year,month,date);
if(day==3)
printf("\n%d-%d-%d is Wednesday!\n",year,month,date);
if(day==4)
printf("\n%d-%d-%d is Thursday!\n",year,month,date);
if(day==5)
printf("\n%d-%d-%d is Friday!\n",year,month,date);
if(day==6)
printf("\n%d-%d-%d is Saturday!\n",year,month,date);
printf("\nContinue...(Y/N)");
con=getch();
if((con=='y')||(con=='Y'))
goto r1;
if((con=='n')||(con=='N'))
main();
}
if(choice==2)
{
r2:system("cls");
printf("\nPlease input the year(XXXX):");
scanf("%d",&year);
flag=isleap(year);
if(flag==1)
printf("\nThe year %d is leap year!\n",year);
if(flag==0)
printf("\nThe year %d is not leap year!\n",year);
printf("\nContinue...(Y/N)");
con=getch();
if((con=='y')||(con=='Y'))
goto r2;
if((con=='n')||(con=='N'))
main();
}
if(choice==3)
{
r3:system("cls");
printf("\nPlease input the year(XXXX):");
scanf("%d",&year);
printcalendar(year);
printf("Continue...(Y/N)");
con=getch();
if((con=='y')||(con=='Y'))
goto r3;
if((con=='n')||(con=='N'))
main();
}
if(choice==4)
{
system("cls");
printf("\nDo you want to Exit?(Y/N)");
con=getch();
if((con=='y')||(con=='Y'))
return;
if((con=='n')||(con=='N'))
main();
}
}
+][/code]
#6
今年Feb月的时候的练习:
#include <stdio.h>
#include <stdbool.h>
//Define Global Variables
int year,month,numberDays,weekFirstDay,lastDay;
int daysPerMonth[12]={ 31,28,31,30,31,30,31,31,30,31,30,31 };
bool leapFlag;
//Declare some Functions in the Program.
void space (void);
void dispcal (void);
bool leapYear (void);
int numbersOfMonth (void);
int weekOfFirstday (void);
int sumDay (int n);
//Main Program Start...
int main (void) {
printf ("please date[year month]:");
scanf ("%i%i",&year,&month);
printf ("\n");
//Call Functions.
//weekOfFirstday():Get week of Current Month First day.
//numbersOfMonth():Get numbers of Current Month.
//dispcal(weekFirstDay):display Cureent month calendar.
weekOfFirstday();
numbersOfMonth();
dispcal();
//Return OS.
return 0;
}
//
int weekOfFirstday (void) {
switch (month) {
case 1: numberDays=1;break;
case 2:numberDays=sumDay(2);break;
case 3:numberDays=sumDay(3);break;
case 4:numberDays=sumDay(4);break;
case 5:numberDays=sumDay(5);break;
case 6:numberDays=sumDay(6);break;
case 7:numberDays=sumDay(7);break;
case 8:numberDays=sumDay(8);break;
case 9:numberDays=sumDay(9);break;
case 10:numberDays=sumDay(10);break;
case 11:numberDays=sumDay(11);break;
case 12:numberDays=sumDay(12);break;
}
if(leapYear()==true&&month>2) {
numberDays+=1;
}
weekFirstDay=((year-1)*365+(year-1)/4-(year-1)/100+(year-1)/400+numberDays)%7;
return weekFirstDay;
}
//
int sumDay (int n) {
int i,sum=1;
for(i=0;i<(n-1);i++) {
sum += daysPerMonth[i];
}
return sum;
}
void space (void) {
int i;
for(i=0;i<weekFirstDay;i++) {
printf ("\t");
}
}
//
void dispcal (void) {
int index,col,firstDay=1;
printf ("---------------------------------------------------\n");
printf ("Sun\tMon\tTue\tWed\tThu\tFri\tSat\n\n");
space();
for(col=1;col<=7-weekFirstDay;col++,firstDay++) {
printf ("%i\t",firstDay);
}
printf ("\n\n");
for(index=1,col=firstDay;col<=lastDay;col++,index++) {
printf ("%i\t",col);
if(index%7==0) {
printf ("\n\n");
}
}
printf ("\n--------------------------------------------------\n");
}
//
bool leapYear (void) {
if(((year%4==0&&year%100!=0)||year%400==0)&&month==2) {
leapFlag=true;
}else{
leapFlag=false;
}
return leapFlag;
}
//
int numbersOfMonth (void) {
if(leapYear()==true) {
lastDay=daysPerMonth[month-1]+1;
}else{
lastDay=daysPerMonth[month-1];
}
return lastDay;
}
root@~/prog #./cale
please date[year month]:2011 6
---------------------------------------------------
Sun Mon Tue Wed Thu Fri Sat
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30
--------------------------------------------------
root@~/prog #
#7
该不会以身相许吧?
#8
就第一个没有错误、那两个都有错误。还有、没有红色字体啊、、一定要有这个的!