在VC下运行
#include <iostream.h>
void main()
{int days=0,year,month,day,n,week,i;
int mont[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
cout<<"Input a date:"<<endl;
cout<<"year:";
cin>>year;
cout<<"month:";
cin>>month;
cout<<"day:";
cin>>day;
if(year%400==0||(year%4==0&&year%100!=0))
mont[2]=29;
for(i=1;i<month;i++)
days+=mont[i];
days+=day;
n=year-1+(year-1)/4-(year-1)/100+(year-1)/400+days;
week=n%7;
cout<<"This date is:";
switch (week)
{case 0: cout<<"Sunday.";break;
case 1: cout<<"Monday.";break;
case 2: cout<<"Tuesday.";break;
case 3: cout<<"Wendesday.";break;
case 4: cout<<"Thursday.";break;
case 5: cout<<"Friday.";break;
case 6: cout<<"Saturday.";break;
}
cout<<endl;
}
俺自己写的万年历 那出来给你看上一眼
#include"stdio.h"
void weekday();
int leap(int);
int _2000yera(int x)
{
int sum=0;
int i;
if(x>=2000){
for(i=2000;i<x;i++)
{
sum+=(i%4==0&&i%100==0||i%400==0)?366:365;
}
return (sum+6)%7;
}
else{
for(i=x;i<2000;i++)
{
sum+=(i%4==0&&i%100==0||i%400==0)?366:365;
}
return (-sum%7+6)%7;
}
}
void weekday()
{
int i;
for(i=1;i<=7;i++)
printf("星期%d\t",i);
printf("\n");
}
int sp(int x)
{
int i;
for(i=1;i<=_2000yera(x);i++)
printf("\t");
return i;
}
int month(int ch,int x)
{
switch(ch)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:return 31;
case 4:
case 6:
case 9:
case 11:return 30;
case 2:return leap(x);
}
}
int leap(int x)
{
int b;
b=(x%4==0&&x%100!=0)||x%400==0?29:28;
return b;
}
int printyear(int x)
{
int mon,i=1,j,day;
printf("*********1月*********");
printf("\n");
weekday();
printf("\n");
i=sp(x);
for(day=1,mon=1;mon<=12;mon++)
{
for(j=1;j<=month(mon,x);j++,i++,day++)
{
printf("%d\t",j);
if(i%7==0){printf("\n");day=1;}
}
if(mon<12){
printf("\n");
printf("*********%d月*********\n",mon+1);
weekday();
printf("\n");
i=1;
i+=day-2;
for(;day-2>0;day--)
printf(" \t");}
}
}
main()
{
int x,exit;
printf("year:");
scanf("%d",&x);
printyear(x);
printf("\n输入任意数字结束:");
scanf("%d",&exit);
}