Fortran程式碼轉C++

Program Calendar ! 1900,1,1 is Tuesday implicit none integer ::counter integer ::year integer ::month integer ::days integer ::week integer :: days_in_a_month(12)=(/31,28,31,30,31,30,31,31,30,31,30,31/) days=2 !1 write (*,*) 'Please input the year' read (*,*)... show more Program Calendar
! 1900,1,1 is Tuesday
implicit none
integer ::counter
integer ::year
integer ::month
integer ::days
integer ::week
integer :: days_in_a_month(12)=(/31,28,31,30,31,30,...
days=2
!1

write (*,*) 'Please input the year'
write (*,*) 'Please input the month'

!use do to calculate the total days
do counter=1900,year-1
days = days + days_in_a_year(counter)
end do

if ( days_in_a_year(year) == 366 ) days_in_a_month(2)=29 !10
if (month /= 1) then

do counter=1,month-1
days=days+ days_in_a_month(counter)
end do
end if
write(*,*)

week=mod(days,7)

write(*,*) "日 一 二 三 四 五 六"
!20
do counter=1,week
write(*,20) ' '
20 format(A3\)
end do

do counter=1,days_in_a_month(month)
write(*,10) counter
10 format(I3\)
if (mod(counter+week,7) == 0 ) write(*,*)
end do
stop
end program Calendar

! the final output process

integer function days_in_a_year(year)
implicit none
integer :: year

!calculate the number of days in a year
!the input year is variable a
if (year == 1900) then
days_in_a_year =0

if (mod(year,4)=0) then
if (mod(year,100)=0) then

if (mod(year,400)=0) then
days_in_a_year =366
else
days_in_a_year =365
end if

else
days_in_a_year =366
end if

else
days_in_a_year =365

end if
return
end