FORTRAN 95でカレンダーを出力するコードです。
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
! 名前 : Myoga Screw-bright (旧名:Myoga S. Tomonaka) | |
! Twitter : https://twitter.com/Myoga1012 | |
program main | |
character*10 dummy(3) | |
integer*4 now(8) | |
integer*4 firstDate | |
integer*4 i, day | |
call date_and_time( dummy(1), dummy(2), dummy(3), now ) | |
! 1日の曜日合わせてオフセットします。 | |
do i = 1, week( now(1), now(2), 1 ) | |
write ( *, fmt = '(a)', advance = 'no' ), " " | |
end do | |
! カレンダーを出力します。 | |
do day = 1, DaysInMonth( now(1), now(2) ) | |
write ( *, fmt = '(I3)', advance = 'no' ), day | |
if ( mod( day + week( now(1), now(2), 1 ), 7 ) == 0 ) then | |
print *, "" | |
else if( day == DaysInMonth( now(1), now(2) ) ) then | |
print *, "" | |
end if | |
end do | |
contains | |
function week( y, m, d ) | |
integer*4 y, m, d, week | |
! Zellerの公式 : Sun = 0, Mon = 1, ... | |
week = mod( y + y / 4 - y / 100 + y / 400 + ( 13 * m + 8 ) / 5 + d, 7 ) | |
end function week | |
function DaysInMonth( y, m ) | |
integer*4 y, m, DaysInMonth | |
! 2月 | |
if ( m == 2 ) then | |
if ( mod( y, 4 ) == 0 ) then | |
DaysInMonth = 29 | |
else | |
DaysInMonth = 28 | |
end if | |
! 1, 3, 5, 7, 8, 10, 12月 | |
else if ( m <= 7 .and. mod( m, 2 ) == 1 .or. m >= 8 .and. mod( m, 2 ) == 0 ) then | |
DaysInMonth = 31 | |
! 4, 6, 9, 11月 | |
else | |
DaysInMonth = 30 | |
end if | |
end function DaysInMonth | |
end program main | |
! Calendar.f95 | |
! Copyright (c) 2014 Myoga-TN.net All Rights Reserved. | |
! This software is released under the MIT License. | |
! http://opensource.org/licenses/mit-license.php |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment