标签:
公式
蔡勒(Zeller)公式,是一个计算星期的公式,随便给一个日期,就能用这个公式推算出是星期几。
1 #include <stdio.h> 2 3 int main() 4 { 5 int year, month, day, c, y, w; 6 char b[7][10] = { "sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday" }; 7 scanf("%d%d%d", &year, &month, &day); 8 if (month < 3) 9 { 10 year--; 11 month += 12; 12 } 13 c = year / 100; 14 y = year % 100; 15 w = (c / 4) - 2 * c + (y + y / 4) + (13*(month + 1) / 5) + day - 1; 16 w = (w % 7 + 7) % 7; 17 puts(b[w]); 18 return 0; 19 }
标签:
原文地址:http://www.cnblogs.com/maxin/p/5536901.html