-
-
Save Nia-TN1012/8030e0c7b8e72fee3c0c890f8aeb7023 to your computer and use it in GitHub Desktop.
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
! 名前 : Nia Tomonaka | |
! Twitter : https://twitter.com/nia_tn1012 | |
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-2023 Nia T.N. Tech Lab. / Chronoir.net. | |
! 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
GitHubのアカウント統合のため、Myoga1012→Nia-TN1012に移行しました。
旧URL: https://gist.github.com/Myoga1012/13f2f70a793ce572e990