黑色星期五
在编这个时怎么确定这一天是星期几?最好简单点,我是菜鸟中的菜鸟。
程序代码:
#include <stdio.h> struct date { int year; int month; int day; int temp; char name[9]; }; const struct date week[7]={ {0,0,0,0,{'S','u','n','d','a','y'}}, {0,0,0,1,{'M','o','n','d','a','y'}}, {0,0,0,2,{'T','u','e','s','d','a','y'}}, {0,0,0,3,{'W','e','d','n','e','s','d','a','y'}}, {0,0,0,4,{'T','h','u','r','s','d','a','y'}}, {0,0,0,5,{'F','r','i','d','a','y'}}, {0,0,0,6,{'S','a','t','u','r','d','a','y'}}, }; int main (void) { struct date thedate; int getDaysOfDate (struct date d); int numberOfWeek,i,j; printf ("Enter date [yyyy mm dd]:"); scanf ("%i %i %i",&thedate.year,&thedate.month,&thedate.day); printf ("The day is : "); numberOfWeek=(getDaysOfDate(thedate)-621049)%7; for(i=0;i<7;i++) { if(week[i].temp==numberOfWeek){ for (j=0;j<9;j++){ printf ("%c",week[i].name[j]); } } } return 0; } int getDaysOfDate (struct date d) { int days; if(d.month<=2) { days=1461*(d.year-1)/4+153*(d.month+13)/5+d.day; }else{ days=1461*d.year/4+153*(d.month+1)/5+d.day; } if(d.year>=1700&&d.month>=3&&d.day>=1 && d.year<=1800&&d.month<=2&&d.day<=28) { days=days+2; } if(d.year>=1800&&d.month>=3&&d.day>=1 && d.year<=1900&&d.month<=2&&d.day<=28) { days=days+1; } return days; }
这两天论坛好慢呀!!!