Created
March 13, 2014 15:10
-
-
Save nanpuyue/9530266 to your computer and use it in GitHub Desktop.
输入日期计算星期
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
program day; | |
var y,a,b,c,e,f:longint; m,d:word; | |
begin write('输入日期(年月日,以空格隔开):'); read(y,m,d); | |
a:=y div 4-y div 100+y div 400; | |
if (((y mod 4=0) and (y mod 100<>0)) or (y mod 400=0)) and ((m=1) or (m=2)) then b:=1 else b:=0; | |
c:=y+a+d-b; | |
case m of | |
1,10:e:=c+6; | |
2,3,11:e:=c+2; | |
4,7,12:e:=c+5; | |
5:e:=c; | |
6:e:=c+3; | |
8:e:=c+1; | |
9:e:=e+4; | |
else writeln ('错误'); end; | |
f:=e mod 7; | |
writeln('这天是星期',f,'( 0 表示星期日)'); | |
end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
这是高中学编程后写的第一个程序。